Skip to content

lib-arc 库参考 ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793652338/FIN+5.3.1+lib-arc 中文整理基于 FIN 5.3.1

导读: Arc 复合文档扩展

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • lib
  • meta
  • docs
  • tags
  • apps
  • funcs
  • views
  • def
  • supertypes
  • subtypes
  • tags
  • enum
  • Overview
  • Structure
  • Custom Types
  • Labels
  • State
  • Display Names
  • Axon
  • Security
  • Attachments
  • Clustering
  • Todo
  • arcDigest(arcs, since: null)
  • arcEdit(orig, changes, part: null)
  • arcEditPart(orig, origPart, partChanges)
  • arcMove(orig, newArcOn)
  • arcNew(meta, part: null)
  • arcNewPart(orig, part)
  • arcRead(id, checked: true)
  • arcReadAllUnder(parent, filter: null)
  • arcRemovePart(orig, origPart)
    • src

概述(中译) ​

Arc 复合文档扩展


API 正文(英文) ​

docs ​

Overview • Structure • Custom Types • Labels • State • Display Names • Axon • Security • Attachments • Clustering • Todo


tags ​

arcArc document
arcLabelBase type for arc document label tags
arcOnSubject of the document
arcPartArc document part
arcPriorityPriority level of the document
arcStateDefines work flow state of an arc document
arcTransitionsState transitions used on an arcState def
arcTypeDocument type which determines workflow
arcTypeDefaultMake an arc type the default selection in the UI
assignedToPerson who is currently responsible for the workflow task
attachmentsList of attachments as URIs in the virtual file tree
byAuthor of a document or part
dueDateDate expected for completion of the workflow task
obsArcsSubscribe to arc document changes - see docs

apps ​

arcViews used to browse and edit arc documents

funcs ​

arcDigestFormat a grid of arc summary records for a notification
arcEditCommit a diff to an existing arc rec
arcEditPartEdit an existing part on a record
arcMoveMove an arc document to another project database based on arcOn ref Return new arc document as grid
arcNewCreate a new arc
arcNewPartAdd a new part to an arc record
arcReadReturn the encoding of an arc and all its parts as a grid
arcReadAllUnderRead summary grid of arcs with an arcOn contained by the given parent
arcRemovePartRemove an existing part on a record

views ​

arcDocRead and edit a single arc document
arcSettingsSettings for the arc extension
arcSummaryBrowse and filter arc documents across the cluster
arcTypesView documentation for the installed arc types


def ​

app:arc ​

Views used to browse and edit arc documents


meta ​

defapp:arc
disKeyui::arc
iconarc
isapp
liblib:arc

supertypes ​

featureFeature namespace of definitions formatted as feature:name
appUI application grouping of views


def ​

arc ​

Arc document


meta ​

defarc
isentity
liblib:arc
mandatory✓

supertypes ​

markerMarker labels a dict with typing information
entityTop-level dicts with a unique identifier

subtypes ​

noteNote is a simple document without workflow
ticketTicket tracks a software or help case
workorderWorkorder tracks maintenance case

tags ​

arcOnSubject of the document
arcTypeDocument type which determines workflow
byAuthor of a document or part
createdThe timestamp when entity was created
disDisplay name for an entity
idDefines the unique identifier of an entity in system using a ref value type
viewLinkView name and state for linking to a saved view


def ​

arcLabel ​

Base type for arc document label tags


meta ​

defarcLabel
ismarker
liblib:arc

supertypes ​

markerMarker labels a dict with typing information

subtypes ​

arcBreakdownMechanical failure
arcBugSoftware defect causing improper behavior
arcDamageEquipment has been physically damaged
arcElectricalTask is electrical in nature
arcEnhancementSoftware request to add new functionality
arcHvacTask is HVAC in nature
arcInspectionEquipment requires inspection
arcMaintenancePreventative or scheduled maintenance task
arcPlumbingTask is plumbing in nature
arcSafetyHazardous situation
arcSupportAssistance required
arcWishWish list for future enhancement


def ​

arcOn ​

Subject of the document


meta ​

defarcOn
isref
liblib:arc
navCluster✓
navSelAnyRec✓
ofpoint
tagOnarc

supertypes ​

valData value type
scalarScalar is an atomic value kind
refReference to an entity


def ​

arcPart ​

Arc document part


meta ​

defarcPart
isdict
liblib:arc

supertypes ​

valData value type
dictMap of name/value tag pairs

tags ​

attachmentsList of attachments as URIs in the virtual file tree
docDocumentation in simplified flavor of markdown


def ​

arcPriority ​

Priority level of the document


meta ​

defarcPriority
enumSee below
isstr
liblib:arc
tagOnticket, workorder

enum ​

criticalUrgent and requires immediate attention
highShould be addressed before other issues
mediumNormal response time
lowNice to resolve when time permits

supertypes ​

valData value type
scalarScalar is an atomic value kind
strUnicode string of characters


def ​

arcState ​

Defines work flow state of an arc document


meta ​

defarcState
isstr
liblib:arc

supertypes ​

valData value type
scalarScalar is an atomic value kind
strUnicode string of characters

subtypes ​

ticketStateWorkflow state for a ticket
workorderStateWorkflow state for a workorder


def ​

arcTransitions ​

State transitions used on an arcState def


meta ​

defarcTransitions
isdict
liblib:arc

supertypes ​

valData value type
dictMap of name/value tag pairs


def ​

arcType ​

Document type which determines workflow


meta ​

defarcType
ischoice
liblib:arc
ofarc
tagOnarc
uiInputui::ChoiceInput

supertypes ​

markerMarker labels a dict with typing information
choiceChoice specifies an exclusive marker selection


def ​

arcTypeDefault ​

Make an arc type the default selection in the UI. This tag is added to the arc subtype def.


meta ​

defarcTypeDefault
ismarker
liblib:arc

supertypes ​

markerMarker labels a dict with typing information


def ​

assignedTo ​

Person who is currently responsible for the workflow task


meta ​

defassignedTo
isref
liblib:arc
navAuxFilternot arcUnassignable
ofuser
tagOnticket, workorder

supertypes ​

valData value type
scalarScalar is an atomic value kind
refReference to an entity


def ​

attachments ​

List of attachments as URIs in the virtual file tree


meta ​

defattachments
islist
liblib:arc
ofuri
tagOnarcPart

supertypes ​

valData value type
listOrdered list of zero or more values


def ​

by ​

Author of a document or part


meta ​

defby
isref
liblib:arc
ofuser
tagOnarc

supertypes ​

valData value type
scalarScalar is an atomic value kind
refReference to an entity

lib arc ​

Overview ​

The arc extension provides a framework for compound documents. Arcs may be used to take notes, communicate between team members, and build custom workflow solutions. We use the term "arc" as the generic term to describe these documents - as in the "arc of a story".

The arc framework is designed from the ground up to allow you to define your own document types and workflows. The arc extension itself defines only the infrastructure and a very basic document type. It is a blank slate.

SkySpark also ships with the arcKit extension which predefines three specific arc types:

  • note: simple doc with no workflow
  • workorder: maintenance/physical workflow
  • ticket: software/support workflow

You can use arcKit directly, customize it with additional tags, or build your own document types from scratch.

Structure ​

Arc documents are stored as normal records in the folio database. A given arc is composed of meta data and zero more parts. The meta data is the record itself and stores summary information such as the display name, arc type, and labels. The parts store the body of the document as a list of dicts.

The meta data is stored in the arc record itself. The following are standardized tags:

  • id: the standard record identifier
  • dis: the subject/summary of the document
  • arc: required marker
  • type: marker tags such as note, workorder, or ticket
  • arcOn: target/subject (typically an equip)
  • by: user id for author of document (managed by system)
  • created: timestamp when document created (managed by system)
  • viewLink: link to view + state
  • dueDate: optional Date when task is due
  • assignedTo: optional user id for current owner
  • arcPriority: optional enum critical, high, medium, low

Arcs contain zero or more parts which store the user generated data. Most of the time each part models a user reply to the document. Parts are stored to disk in blobs like history data and the spark/KPI cache. Each part is a dict which uses the following tags:

  • ts: timestamp when the part is created (managed by system)
  • by: user id for author (managed by system)
  • audit: Dict for tag/state transitions (managed by system)
  • doc: fandoc comment
  • attachments: Uri or Uri[] to virtual files

Custom Types ​

The arc extension defines only the generic document base type. Enable the arcKit extension to use the predefined note, workorder, and ticket types. Or you can use these document types as templates for your own custom document types. Document types are created and customized using Haystack definitions. Use the Arc | Types view to see how the defs work.

To create a new document type, create a subtype of arc as follows:

// custom document type
def: ^myDocType
is: ^arc
dis: "My Doc Type"
icon: "box"
doc: "Description of my document type"

All documents support the dis and arcOn tag. In addition the created and by tags are automatically managed for you. Register additional tags for your document type via tagOn:

// add standard tags to your document type using defx
defx: ^assignedTo
tagOn: ^myDocType

// add custom tag to your document type
def: ^myDocCustomTag
dis: "My Doc Custom Tag"
is: ^str
tagOn: ^myDocType
doc: "Description of the custom tag"

Custom document types and associated tags should be prefixed to ensure they are uniquely named. Do not use generic names which run the risk of future naming collisions. You can simplify the display name of the document type and tags even when using prefixed programmatic names.

Labels ​

Labels are special markers registered on a given arc document type. The UI allows users to easily click on/off zero or more labels to apply these markers to their documents. The arcKit extension predefines several labels.

Label definitions are just standard defs which subtype from arcLabel and are registered on a document type using tagOn:

def: ^myCustomLabel
is: ^arcLabel
dis: "Custom Label"
tagOn: ^myDocType
color: "#e74c3c"
doc: "Description of the custom label"

The color tag is used to display the label "pill shape" background. The text foreground is always white, so choose a darker color for your label colors. Just like other tags, make sure to use a unique prefix to avoid naming collisions.

State ​

Custom workflows are defined using a state tag. Workflow are modeled as a Finite State Machine. The workflow is defined as a mathematical graph of discrete states and valid transitions between those states.

A workflow is attached to a document type with a def which is a specialized enum subtyping from arcState. Here is a very simple open/closed workflow graph:

def: ^myDocTypeState
is: ^arcState
tagOn: ^myDocType
doc: "Description of state"
enum: Trio:
  open:   { dis:"Open", icon:"warn",  iconColor:"#db311f", doc:"Open description" required:[^assignedTo]}
  closed: { dis:"Closed", icon:"check", iconColor:"#1ca355", doc:"Closed description"}
arcTransitions: Trio:
  new:    { from: [^start],  to:^open }
  close:  { from: [^open],   to:^closed }
  reopen: { from: [^closed], to:^open }

By convention the state tag should be the document type name suffixed with "State". It is registered on document tag using tagOn.

The enum tag defines the states as nested dicts. Each state should define the following tags:

  • dis: display name for state
  • icon: logical icon name for the state
  • iconColor: color to use for outline version of the icon
  • doc: human description of the state
  • assignedTo: optional list of tag name symbols which must be set on the record to transition into this state

The arcTransitions tag defines the valid transitions. There must be a transition defined in order to change from one state to another. Transitions are defined as a nested dicts with the following tags:

  • from: list of symbols for one or more from state names; ^start is used to indicate a transition which may be used when the document is first created
  • to: symbol for the state name we transition to
  • dis: display name for the transition to show in the UI
  • admin: marker to indicate that only admin users may make this transition
  • su: marker to indicate that only superusers users may make this transition

Transition access also requires the arcWriteAccess edit and newPart permissions.

Display Names ​

The Arc UI is driven off the Haystack defs. As an end user application, it is desirable to use nice display names as opposed to camel case programmatic names. The following rules are used to determine the display name of a tag:

  1. Use dis tag if defined
  2. Use disKey tag as localization key if defined
  3. Use disMacro if defined
  4. Check localization key ui::{name}
  5. Fallback to programmatic name

Since many common terms have ui localization keys, you will find you can often omit the dis tag. If you are defining document types for international usage, then consider using disKey to ensure your tag library is localizable.

Axon ​

Arc documents are fully scriptable with Axon. You will work with documents in two modes:

  • summary mode: using just the records themselves with meta data only
  • details mode: working with the full document and all its parts

You will use standard read operations to work in summary mode such as readAll() or xqReadAll():

// read all documents from local database
readAll(arc)

// read all workorders with the maintenance label
readAll(arc and workorder and arcMaintenance)

// read all tickets across the cluster
xq().xqReadAll(arc and ticket).xqExecute

To read the document details use the arcRead() function. This returns the document as a grid where the grid meta models the record/meta data and each row of the grid models one part:

// read a document as a grid by id
arcRead(id)

The following functions are used to create and modify documents:

  • arcNew(): create a new document
  • arcEdit(): modify an existing document or add a new part
  • arcNewPart(): add a part to an existing document
  • arcEditPart(): modify a part of an existing document
  • arcRemovePart(): remove a part from an existing document
  • arcMove(): move document to a new node on the cluster (discussed in Clustering)

Examples:

// create a new document with an initial part
arc: arcNew({note, dis:"New note"}, {doc:"Initial comment"})

// add new comment part to existing arc
arc = readById(arc.meta->id).arcNewPart({doc:"New comment"})

// modify the comment from previous commit;
// note here are passing arc rec as the document grid meta
// and the part as a row from the document grid;
arc = arcEditPart(arc.meta, arc[-1], {doc:"Modify the comment"})

// remove the last part
arc = arcRemovePart(arc.meta, arc[-1])

When scripting as an admin, you can also use normal commit() calls to create/edit the record metadata. However you must arcNew() and arcNewPart() to add new parts since they are stored separately from the record.

Security ​

Both read and write access for all users requires:

  • Access to the arc record via the arcAccessFilter
  • Access to the arcOn target via normal filters (siteAccessFilter, equipAccessFilter, etc)

Those two tags define the standard Folio level read/write permissions. Additionally the UI and Axon modification functions are further refined by the arcWriteAccess user tag. This tag is formatted as a comma-separated list of the following permissions:

  • "new": can create a new arc document
  • "edit": can edit the record meta of an existing arc document
  • "move": can move a document to a new project based on arcOn
  • "remove": can trash or remove documents from database
  • "newPart": can add a new part/reply to an arc document
  • "editPart": can edit/remove existing parts/replies of an arc document

If not configured, then users default as follows:

  • su: "new, edit, move, remove, newPart, editPart" (all permissions)
  • admin: "new, edit, move, remove, newPart" (no editPart)
  • op: "" (none)

State transitions require both the "edit" and "newPart" permissions.

The following tags can never be set directly on a part:

  • by: user id
  • ts: timestamp
  • audit: dict

With the exception of the above tags, admin users can set any tag they want on a part. Operators can only set tags with an explicit tag definition registered on the document type, or set tags on a part that are registered as a tag on arcPart.

Note: that the arcWriteAccess may be used to elevate operator permissions and lower su/admin permissions. However this tag has no effect on a user's normal commit level permissions - su/admin always have access to modify the record/meta data itself directly.

Attachments ​

Attachments in arcs are disabled by default. In order to enable this feature you must configure the attachmentPath unders Settings | Arc. The value must be an absolute path to a directory in the virtual file system. All attachments will be stored to this directory.

Note in a clustered environment then the attachments directory must be accessible to all nodes where the arcs will be accessed. It is recommended to use a cloud storage directory such as DropBox or GoogleDrive for clustered environments.

Clustering ​

The arc extension is fully integrated into SkySpark's clustering architecture. When an arc is created it is stored in the same project where the arcOn target record is located. This provides several advantages:

  • its a natural way to perform load balancing/sharding
  • it means arcs are co-located with the equip/point data
  • arc availability matches the target equip availability

Because of this design, it is disallowed to change the arcOn tag to reference to a record in another project. The system will detect this case and show a error that you must use a "Move" command. The "Move" command inputs a new arcOn reference and then moves the arc to that target's project database. The relative portion of the arc's id remains the same, however the absolute id will reflect the new project database.

Another aspect to consider with clustering is how replicas are utilized. Replicas are readonly copies of a project database which might be slightly behind the current state of the master project. When working with arcs the following rules are used:

  • Arc | Summary view always uses replicas (see todo below)
  • Arc | Doc view uses the master if available or falls back to replica if master is down
  • Arc edits require access to the master project

Because of how replicas work, its possible to view an arc from a replica database even when the master project is down. When this occurs the arc is readonly and any attempts to perform a modification will show an error dialog.

Todo ​

There are several features still planned to fill in some of the missing holes:

  • Use replicas only for the Arc | Summary view can cause out-of-sync issues because this view won't reflect the current state of the arcs until the next replica sync. We are going to enhance this view to fetch the latest changes from the master when its available so it always reflects the current up-to-date data
  • In a clustered environment, ideally there should be a user account on every node for all users which might be configured as the assignedTo tag. The assignedTo tag picker will browse the user database based on the node currently used by the UI. However if an arc exists on a node where that user is not present in the user database, then no display name will be available for the user and the field will display "u:username". Edits to records in this state will show a lint warning. But otherwise everything will continue to work correctly.


def ​

dueDate ​

Date expected for completion of the workflow task


meta ​

defdueDate
isdate
liblib:arc
tagOnticket, workorder

supertypes ​

valData value type
scalarScalar is an atomic value kind
dateISO 8601 date as year, month, day


def ​

func:arcDigest ​

arcDigest(arcs, since: null) ​

Format a grid of arc summary records for a notification. If since parameter is a span, then all arcs and parts that have been modified in that span are returned. Otherwise, if since is a DateTime, then all arcs and parts from that time until now are returned.

// read digest for all arcs which have been updated since midnight
readAll(arc).arcDigest(dateTime(today(), 0:00))

meta ​

deffunc:arcDigest
isfunc
liblib:arc
namearcDigest

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcEdit ​

arcEdit(orig, changes, part: null) ​

Commit a diff to an existing arc rec. Orig must be an arc record. If part is non-null, then it is a dict with new part to add the arc. Return new arc document as grid. See arc.


meta ​

deffunc:arcEdit
isfunc
liblib:arc
namearcEdit

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcEditPart ​

arcEditPart(orig, origPart, partChanges) ​

Edit an existing part on a record. Orig must be an arc record. The origPart must be a dict with the current part which you can get from the arcRead() grid. The partChanges must be a dict diff with the tags to modify. Return new arc document as grid. This function requires current user to have "editPart" permission. See arc.


meta ​

deffunc:arcEditPart
isfunc
liblib:arc
namearcEditPart

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcMove ​

arcMove(orig, newArcOn) ​

Move an arc document to another project database based on arcOn ref Return new arc document as grid.


meta ​

deffunc:arcMove
isfunc
liblib:arc
namearcMove

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcNew ​

arcNew(meta, part: null) ​

Create a new arc. Return new arc document as grid. See arc.


meta ​

deffunc:arcNew
isfunc
liblib:arc
namearcNew

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcNewPart ​

arcNewPart(orig, part) ​

Add a new part to an arc record. Orig must be an arc record and part must be a dict with the new part tags. Return new arc document as grid. This function requires current user to have "newPart" permission. See arc.


meta ​

deffunc:arcNewPart
isfunc
liblib:arc
namearcNewPart

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcRead ​

arcRead(id, checked: true) ​

Return the encoding of an arc and all its parts as a grid. This function inserts a synthetic arcProjStatus tag into the grid meta along with the arc record itself. See arc.


meta ​

deffunc:arcRead
isfunc
liblib:arc
namearcRead

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcReadAllUnder ​

arcReadAllUnder(parent, filter: null) ​

Read summary grid of arcs with an arcOn contained by the given parent. For example given a site, this will return all arcs on the children spaces, equip, and points via the siteRef. This function only reads from the local project. The optional filter may be used to specify additional filtering of the results.

Example:

// read all arcs under a given site
read(site).arcReadAllUnder

// read open workorders under a given site
read(site).arcReadAllUnder(workorder and workorderState=="open")

meta ​

deffunc:arcReadAllUnder
isfunc
liblib:arc
namearcReadAllUnder

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:arcRemovePart ​

arcRemovePart(orig, origPart) ​

Remove an existing part on a record. Orig must be an arc record. The origPart must be a dict with the current part which you can get from the arcRead() grid. Return new arc document as grid. This function requires current user to have "editPart" permission. See arc.


meta ​

deffunc:arcRemovePart
isfunc
liblib:arc
namearcRemovePart

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

obsArcs ​

Subscribe to arc document changes - see docs


meta ​

defobsArcs
isobsRecs
liblib:arc

supertypes ​

markerMarker labels a dict with typing information
observableObservable subscription - see docs
obsRecsBase class for observables on database records

tags ​

obsFilterFilter string to define the record data set observed


def ​

view:arcDoc ​

Read and edit a single arc document.

You may hide specific toolbar buttons in custom views by defining a node with the hidden meta tag. Toolbar component names that may be hidden:

  • transition
  • reply
  • edit
  • move
  • trash
  • sortReplies
  • projStatus

For example to hide the trash toolbar command:

trash: {hidden}

meta ​

appNamearc
defview:arcDoc
disKeyui::doc
iconview
isview
liblib:arc
order110

supertypes ​

featureFeature namespace of definitions formatted as feature:name
viewFresco UI view

src ​

view:        { uiType:"arcExt::ArcDocView" }
arc:         { var kind:"Ref<arc>" defVal:@null share }
transition:  { action:"arcEdit" }
reply:       { action:"arcEdit" }
edit:        { action:"arcEdit" }
move:        { action:"arcMove" }
trash:       { action:"arcTrash" }
sortReplies: { var }
projStatus:  { var }
filter:      { var kind:"Str" defVal:"" share }
search:      { var kind:"Str" defVal:"" share }
sortCol:     { var kind:"Str" share }
sortDir:     { var kind:"Str" share }
data:        { expr:"arcRead({{arc}}, false)" }


def ​

view:arcSettings ​

Settings for the arc extension


meta ​

admin✓
appNamesettings
defview:arcSettings
disKeyui::arc
iconview
isview
liblib:arc

supertypes ​

featureFeature namespace of definitions formatted as feature:name
viewFresco UI view

src ​

view:   {inherit:"form"}
submit: {action:"extSettingsCommit"}
data:   {expr:"extSettings(\"arc\")"}


def ​

view:arcSummary ​

Browse and filter arc documents across the cluster.

You may bind the arcUnderRef variable to a site/equip/space ref which adds an and clause to the filter to include only arcs under the given ref. Note that if the standard filter varaible also has an arc under clause then the two are anded together.

You may hide specific toolbar buttons in custom views by defining a node with the hidden meta tag. Toolbar component names that may be hidden:

  • favs
  • filter
  • new
  • trash
  • search

For example to hide the trash toolbar command:

trash: {hidden}

meta ​

appNamearc
defview:arcSummary
disKeyui::summary
iconview
isview
liblib:arc
order100

supertypes ​

featureFeature namespace of definitions formatted as feature:name
viewFresco UI view

src ​

view:        { uiType:"arcExt::ArcSummaryView" }
arc:         { var kind:"Ref<arc>" defVal:@null share }
favs:        { var }
filter:      { input var kind:"Str" defVal:"" share }
new:         { action:"arcNew" }
trash:       { action:"arcTrash" }
search:      { input var kind:"Str" defVal:"" share }
sortCol:     { var kind:"Str" share }
sortDir:     { var kind:"Str" share }
arcUnderRef: { var kind:"Ref" defVal:@null }
data:        { expr:"arcSummary({{filter}}, { search:{{search}}, arcUnderRef:{{arcUnderRef}} })" }


def ​

view:arcTypes ​

View documentation for the installed arc types


meta ​

appNamearc
defview:arcTypes
disKeyui::types
iconview
isview
liblib:arc
order800

supertypes ​

featureFeature namespace of definitions formatted as feature:name
viewFresco UI view

src ​

view: { uiType:"arcExt::ArcTypesView" }