@riboseinc/paneron-registry-kit 2.2.0 → 2.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riboseinc/paneron-registry-kit",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "main": "index.js",
5
5
  "author": "Ribose Inc. <open.source@ribose.com>",
6
6
  "scripts": {
package/types/cr.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import type React from 'react';
3
3
  import type { ProposalSet } from './proposal';
4
4
  import { type RegisterStakeholder } from './stakeholder';
5
+ import type { RegisterItem } from './item';
5
6
  export declare function isSubmittedBy(stakeholder: RegisterStakeholder, cr: Base): boolean;
6
7
  /** Used in place of enum for convenience. */
7
8
  export declare const State: {
@@ -51,6 +52,14 @@ export interface Base<S extends StateType = StateType> {
51
52
  }
52
53
  export declare function isCreatedBy(stakeholder: RegisterStakeholder, cr: Base): boolean;
53
54
  export declare function canBeEditedBy(stakeholder: RegisterStakeholder, cr: Base): boolean;
55
+ /** Proposal structure for single-file proposal import format. */
56
+ export interface ImportableCR {
57
+ /** Proposal data. */
58
+ proposalDraft: Drafted;
59
+ /** Register item data for additions & clarifications. */
60
+ itemPayloads: Record<string, RegisterItem<any>>;
61
+ }
62
+ export declare function isImportableCR(val: any): val is ImportableCR;
54
63
  /**
55
64
  * A change request in any state.
56
65
  * Contains a superset of all possible properties, but all optional.
package/types/cr.js CHANGED
@@ -8,6 +8,7 @@ exports.isState = isState;
8
8
  exports.isEditableState = isEditableState;
9
9
  exports.isCreatedBy = isCreatedBy;
10
10
  exports.canBeEditedBy = canBeEditedBy;
11
+ exports.isImportableCR = isImportableCR;
11
12
  exports.isDrafted = isDrafted;
12
13
  exports.isProposed = isProposed;
13
14
  exports.isWithdrawn = isWithdrawn;
@@ -71,6 +72,11 @@ function canBeEditedBy(stakeholder, cr) {
71
72
  return isCreatedBy(stakeholder, cr) && isEditableState(cr.state);
72
73
  }
73
74
 
75
+ function isImportableCR(val) {
76
+ // TODO: More complete check
77
+ return val.proposalDraft.id && isDrafted(val.proposalDraft) && Object.keys(val.itemPayloads).length > 0;
78
+ }
79
+
74
80
  function isDrafted(cr) {
75
81
  return isInState(cr, State.DRAFT);
76
82
  }
package/types/cr.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cr.js","sourceRoot":"","sources":["../../src/types/cr.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAQ1D,MAAM,UAAU,aAAa,CAAC,WAAgC,EAAE,EAAQ;IACtE,OAAO;IACL,6BAA6B;IAC7B,WAAW,CAAC,iBAAiB,KAAK,EAAE,CAAC,sCAAsC,CAAC,CAAC;AACjF,CAAC;AAID,wBAAwB;AACxB,wBAAwB;AACxB,wBAAwB;AAExB,6CAA6C;AAC7C,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,iCAAiC,EAAE,6BAA6B;IAChE,0BAA0B,EAAE,4BAA4B;IACxD,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,6BAA6B;IACvC,kBAAkB,EAAE,oBAAoB;IACxC,0BAA0B,EAAE,4BAA4B;IACxD,gBAAgB,EAAE,kBAAkB;CAC5B,CAAC;AAIX,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAgB,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,KAAK,CAAC,KAAK;IACX,KAAK,CAAC,0BAA0B;CACxB,CAAC;AAIX,MAAM,UAAU,eAAe,CAAC,KAAgB;IAC9C,OAAO,aAAa,CAAC,OAAO,CAAC,KAA0B,CAAC,IAA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ions. */\n\nimport type React from 'react';\nimport type { ProposalSet } from './proposal';\nimport { type RegisterStakeholder } from './stakeholder';\n\n\n\nexport function isSubmittedBy(stakeholder: RegisterStakeholder, cr: Base): boolean {\n return (\n //isSubmitter(stakeholder) &&\n stakeholder.gitServerUsername === cr.submittingStakeholderGitServerUsername);\n}\n\n\n\n// =====================\n// Change request states\n// =====================\n\n/** Used in place of enum for convenience. */\nexport const State = {\n DRAFT: 'draft',\n PROPOSED: 'proposed',\n SUBMITTED_FOR_CONTROL_BODY_REVIEW: 'pending-control-body-review',\n RETURNED_FOR_CLARIFICATION: 'returned-for-clarification',\n WITHDRAWN: 'withdrawn',\n ACCEPTED: 'accepted',\n REJECTED: 'rejected',\n APPEALED: 'rejection-appealed-to-owner',\n ACCEPTED_ON_APPEAL: 'accepted-on-appeal',\n REJECTION_UPHELD_ON_APPEAL: 'rejection-upheld-on-appeal',\n APPEAL_WITHDRAWN: 'appeal-withdrawn',\n} as const;\n\nexport type StateType = typeof State[keyof typeof State];\n\nexport function isState(val: string): val is StateType {\n return Object.values(State).indexOf(val as StateType) >= 0;\n}\n\n/** A subset of `State` that represents editable states. */\nexport const EditableState = [\n State.DRAFT,\n State.RETURNED_FOR_CLARIFICATION,\n] as const;\n\nexport type EditableStateType = StateType & typeof EditableState[number];\n\nexport function isEditableState(state: StateType): state is EditableStateType {\n return EditableState.indexOf(state as EditableStateType) >= 0;\n}\n\n\n\n// ======================\n// Change request classes\n// ======================\n\n/**\n * Base change request type.\n *\n * Note that e.g. type Base<typeof State.DRAFT> does not equal to Drafted\n * because Drafted includes additional information (namely, SubmitterInput).\n *\n * If the state of a CR matters, this type should not be used directly\n * and concrete types should be used instead.\n */\nexport interface Base<S extends StateType = StateType>\n{\n id: string;\n // decision: typeof Decision[keyof typeof Decision]\n // disposition?: typeof Disposition[keyof typeof Disposition]\n state: S;\n\n /**\n * Used to match against stakeholders declared in register metadata.\n */\n submittingStakeholderGitServerUsername: string;\n\n items: ProposalSet;\n\n /**\n * Against to which register version changes were proposed.\n */\n registerVersion: string;\n\n /**\n * A link to external discussion.\n */\n externalDiscussionURI?: string;\n}\n\n\nexport function isCreatedBy(stakeholder: RegisterStakeholder, cr: Base): boolean {\n return stakeholder.gitServerUsername === cr.submittingStakeholderGitServerUsername;\n}\n\nexport function canBeEditedBy(stakeholder: RegisterStakeholder, cr: Base): boolean {\n return isCreatedBy(stakeholder, cr) && isEditableState(cr.state);\n}\n\n\n/**\n * A change request in any state.\n * Contains a superset of all possible properties, but all optional.\n * XXX: ^^^ This is a lie. Should be changed from | to & with Partial<>?\n */\nexport type SomeCR = \n | Drafted\n | Proposed\n | Withdrawn\n | ReturnedForClarificationByManager\n | SubmittedForControlBodyReview\n | ReturnedForClarificationByControlBody\n | Accepted\n | Rejected\n | RejectionUpheld\n | AcceptedOnAppeal\n | RejectedWithAppealWithdrawn;\n\nexport type Withdrawable =\n | Proposed\n | SubmittedForControlBodyReview\n | ReturnedForClarificationByManager\n | ReturnedForClarificationByControlBody;\n\nexport type Proposable =\n | Drafted\n | ReturnedForClarificationByManager\n | ReturnedForClarificationByControlBody;\n\nexport type SomeEditable =\n | Drafted\n | ReturnedForClarificationByManager\n | ReturnedForClarificationByControlBody;\n\nexport type Disposed =\n | Withdrawn\n | Accepted\n | Rejected\n | AcceptedOnAppeal\n | RejectionUpheld;\n\n\n// More specific change request types.\n// TODO: Refactor to avoid confusiong between current state e.g. Proposed)\n// and type (Proposed, to which all inheriting classes also conform)\n\nexport interface Drafted extends\n SubmitterInput,\n Base<typeof State.DRAFT> { timeStarted: Date, timeEdited: Date }\nexport function isDrafted(cr: Base): cr is Drafted {\n return isInState(cr, State.DRAFT);\n}\n\nexport interface Proposed extends\n Omit<Drafted, 'state'>,\n Base<typeof State.PROPOSED> { timeProposed: Date }\nexport function isProposed(cr: Base): cr is Proposed {\n return isInState(cr, State.PROPOSED);\n}\n\nexport interface Withdrawn extends\n Omit<Withdrawable, 'state'>,\n Base<typeof State.WITHDRAWN> { timeDisposed: Date }\nexport function isWithdrawn(cr: Base): cr is Withdrawn {\n return isInState(cr, State.WITHDRAWN);\n}\n\nexport function hadBeenProposed(cr: Base): cr is Base & { timeProposed: Date } {\n return cr && cr.hasOwnProperty('timeProposed') && !!(cr as Proposed).timeProposed;\n}\nexport function isDisposed(cr: Base): cr is Base & { timeDisposed: Date } {\n return cr && cr.hasOwnProperty('timeDisposed') && !!(cr as Disposed).timeDisposed;\n //return [\n // State.WITHDRAWN,\n // State.ACCEPTED,\n // State.REJECTED,\n // State.REJECTION_UPHELD_ON_APPEAL,\n // State.ACCEPTED_ON_APPEAL,\n //].some(s => cr.state === s);\n}\n\nexport interface SubmittedForControlBodyReview extends\n Omit<Proposed, 'state'>,\n RegisterManagerInput,\n Base<typeof State.SUBMITTED_FOR_CONTROL_BODY_REVIEW> {}\n\nexport interface ReturnedForClarificationByManager extends\n Omit<Proposed, 'state'>,\n RegisterManagerInput,\n Base<typeof State.RETURNED_FOR_CLARIFICATION> {}\n\nexport interface ReturnedForClarificationByControlBody extends\n Omit<SubmittedForControlBodyReview, 'state'>,\n ControlBodyInput,\n Base<typeof State.RETURNED_FOR_CLARIFICATION> {}\n\nexport interface Accepted extends\n Omit<SubmittedForControlBodyReview, 'state'>,\n ControlBodyInput,\n Base<typeof State.ACCEPTED> { timeDisposed: Date }\nexport function isAccepted(cr: Base): cr is Accepted {\n return isInState(cr, State.ACCEPTED);\n}\n\nexport interface Rejected extends\n Omit<SubmittedForControlBodyReview, 'state'>,\n ControlBodyInput,\n Base<typeof State.REJECTED> { timeDisposed: Date }\n\nexport interface Appealed extends\n Omit<Rejected, 'state' | 'timeDisposed'>,\n AppealRequest,\n Base<typeof State.APPEALED> { timeDisposed: undefined }\nexport function isAppealed(cr: Base): cr is Appealed {\n return isInState(cr, State.APPEALED);\n}\n\nexport interface RejectionUpheld extends\n Omit<Appealed, 'state' | 'timeDisposed'>,\n RegisterOwnerInput,\n Base<typeof State.REJECTION_UPHELD_ON_APPEAL> { timeDisposed: Date }\n\nexport interface AcceptedOnAppeal extends\n Omit<Appealed, 'state' | 'timeDisposed'>,\n RegisterOwnerInput,\n Base<typeof State.ACCEPTED_ON_APPEAL> { timeDisposed: Date }\nexport function isAcceptedOnAppeal(cr: Base): cr is AcceptedOnAppeal {\n return isInState(cr, State.ACCEPTED_ON_APPEAL);\n}\n\nexport interface RejectedWithAppealWithdrawn extends\n Omit<Appealed, 'state' | 'timeDisposed'>,\n Base<typeof State.APPEAL_WITHDRAWN> { timeDisposed: Date }\n\n\n\n// Input required when transitioning to different states\n\nexport interface SubmitterInput {\n justification: string;\n}\nexport function hasSubmitterInput(val: any): val is SubmitterInput {\n return val.hasOwnProperty('justification') && typeof val.justification === 'string';\n}\nexport interface RegisterManagerInput {\n registerManagerNotes: string;\n}\nexport function hasRegisterManagerInput(val: any): val is RegisterManagerInput {\n return val.hasOwnProperty('registerManagerNotes') && typeof val.registerManagerNotes === 'string';\n}\nexport interface ControlBodyInput {\n controlBodyNotes: string;\n}\nexport function hasControlBodyInput(val: any): val is ControlBodyInput {\n return (\n val.hasOwnProperty('controlBodyNotes') && typeof val.controlBodyNotes === 'string' &&\n val.hasOwnProperty('controlBodyDecisionEvent') && typeof val.controlBodyDecisionEvent === 'string');\n}\nexport interface AppealRequest {\n appealReason: string;\n}\nexport function hasAppealRequest(val: any): val is AppealRequest {\n return val.hasOwnProperty('appealReason') && typeof val.appealReason === 'string';\n}\nexport interface RegisterOwnerInput {\n registerOwnerNotes: string;\n}\nexport function hasRegisterOwnerInput(val: any): val is RegisterOwnerInput {\n return val.hasOwnProperty('registerOwnerNotes') && typeof val.registerOwnerNotes === 'string';\n}\n\nexport type StateInput =\n | SubmitterInput\n | RegisterManagerInput\n | ControlBodyInput\n | AppealRequest\n | RegisterOwnerInput;\n\n\n/** \n * CR type guard helper.\n * Normally you would not use it directly and instead use\n * more specific is[Type]() helper from this module.\n *\n * Checks CR type using the `state` property.\n * Does not validate other properties.\n *\n * Usage:\n *\n * @example\n * ```ts\n * let someCR;\n * if (isInState<Drafted>(someCR, State.DRAFT)) {\n * // Can assume someCR is Drafted\n * }\n * ```\n *\n * It’ll try to tell you if you mismatch those.\n *\n * @example\n * Will not compile:\n * ```ts\n * let someCR;\n * if (isInState<Drafted>(someCR, State.PROPOSED)) {\n * // Compile error\n * // because State.PROPOSED is not a possible value of Drafted[\"state\"]\n * }\n * ```\n *\n * @example\n * Incorrect usage (do not do this):\n * ```ts\n * let someCR;\n * if (isInState(someCR, State.DRAFT)) {\n * // Can NOT assume someCR is Drafted\n * // The compiler must know the expected concrete CR type\n * }\n * ```\n */\nfunction isInState<CR extends Base>(cr: Base, s: CR[\"state\"]): cr is CR {\n return cr.state === s;\n}\n\n\n\n\n// ===========\n// Transitions\n// ===========\n\n/**\n * A function that transitions CR1 to CR2.\n *\n * The function is declared to return the object\n * without the `state` field, it is set\n * by common wrapper function to reduce duplication.\n */\nexport type Transition<\n /** From CR of this subtype */\n CR1 extends Base,\n /** To CR of this subtype */\n CR2 extends Base,\n /** Using this extra information */\n P extends Record<string, any> | null = null,\n> = (cr: CR1, payload: P) => Omit<CR2, 'state'>;\n\n\n/**\n * Describes a transition.\n *\n * @typeParam CR1: Change request source state type\n * @typeParam CR2: Change request target state type\n * @typeParam P: Extra input needed to transition, if any\n */\nexport interface TransitionConfig<CR1 extends Base, CR2 extends Base, P extends Record<string, any> | null = null> {\n /**\n * Function that implements the transition.\n * Takes a CR in the original state and returns CR in the new state.\n * Additionally, takes appropriate payload, if any, for the transition\n * (e.g., register manager or control body notes).\n *\n * For function implementor:\n *\n * - Function MUST NOT modify CR in place.\n * - Function should throw if submitted payload does not conform to requirements.\n */\n func: Transition<CR1, CR2, P>;\n\n targetState: CR2[\"state\"];\n\n /** Title. Use verb. */\n title: string;\n\n hint?: string | JSX.Element;\n\n /** Widget that can be used to view or enter extra input. */\n Widget: P extends null ? null : React.FC<{ value: P, onChange?: (userInput: P) => void }>;\n\n /**\n * Function that returns true\n * if given stakeholder can perform this transition on given CR.\n */\n canBeTransitionedBy: (stakeholder: RegisterStakeholder, cr: CR1) => boolean;\n}\n\n\n// type TransitionSpec = {\n// [S1 in StateType]?: {\n// [S2 in StateType]?: Transition<Base<S1>, Base<S2>, Record<string, any>>\n// }\n// }\n\n\n/**\n * Source of truth for available transitions.\n * When updating change request business logic,\n * this is the type that should be modified.\n *\n * It will cause compile errors until transition implementation\n * is updated correspondingly.\n */\nexport type Transitions = {\n [State.DRAFT]: {\n // [State.DRAFT]:\n // TransitionConfig<Drafted, Drafted, SubmitterInput>;\n [State.WITHDRAWN]:\n TransitionConfig<Proposed, Withdrawn>;\n [State.PROPOSED]:\n TransitionConfig<Drafted, Proposed, SubmitterInput>;\n };\n [State.PROPOSED]: {\n [State.WITHDRAWN]:\n TransitionConfig<Proposed, Withdrawn>;\n [State.SUBMITTED_FOR_CONTROL_BODY_REVIEW]:\n TransitionConfig<Proposed, SubmittedForControlBodyReview, RegisterManagerInput>;\n [State.RETURNED_FOR_CLARIFICATION]:\n TransitionConfig<Proposed, ReturnedForClarificationByManager, RegisterManagerInput>;\n };\n [State.SUBMITTED_FOR_CONTROL_BODY_REVIEW]: {\n [State.WITHDRAWN]:\n TransitionConfig<SubmittedForControlBodyReview, Withdrawn>;\n [State.RETURNED_FOR_CLARIFICATION]:\n TransitionConfig<SubmittedForControlBodyReview, ReturnedForClarificationByControlBody, ControlBodyInput>;\n [State.REJECTED]:\n TransitionConfig<SubmittedForControlBodyReview, Rejected, ControlBodyInput>;\n [State.ACCEPTED]:\n TransitionConfig<SubmittedForControlBodyReview, Accepted, ControlBodyInput>;\n };\n [State.RETURNED_FOR_CLARIFICATION]: {\n [State.PROPOSED]:\n TransitionConfig<ReturnedForClarificationByManager | ReturnedForClarificationByControlBody, Proposed, SubmitterInput>;\n [State.WITHDRAWN]:\n TransitionConfig<ReturnedForClarificationByManager | ReturnedForClarificationByControlBody, Withdrawn>;\n };\n [State.REJECTED]: {\n [State.APPEALED]:\n TransitionConfig<Rejected, Appealed, AppealRequest>;\n };\n [State.APPEALED]: {\n [State.APPEAL_WITHDRAWN]:\n TransitionConfig<Appealed, RejectedWithAppealWithdrawn>;\n [State.ACCEPTED_ON_APPEAL]:\n TransitionConfig<Appealed, AcceptedOnAppeal, RegisterOwnerInput>;\n [State.REJECTION_UPHELD_ON_APPEAL]:\n TransitionConfig<Appealed, RejectionUpheld, RegisterOwnerInput>;\n };\n}\n"]}
1
+ {"version":3,"file":"cr.js","sourceRoot":"","sources":["../../src/types/cr.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAS1D,MAAM,UAAU,aAAa,CAAC,WAAgC,EAAE,EAAQ;IACtE,OAAO;IACL,6BAA6B;IAC7B,WAAW,CAAC,iBAAiB,KAAK,EAAE,CAAC,sCAAsC,CAAC,CAAC;AACjF,CAAC;AAID,wBAAwB;AACxB,wBAAwB;AACxB,wBAAwB;AAExB,6CAA6C;AAC7C,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,iCAAiC,EAAE,6BAA6B;IAChE,0BAA0B,EAAE,4BAA4B;IACxD,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,6BAA6B;IACvC,kBAAkB,EAAE,oBAAoB;IACxC,0BAA0B,EAAE,4BAA4B;IACxD,gBAAgB,EAAE,kBAAkB;CAC5B,CAAC;AAIX,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAgB,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,KAAK,CAAC,KAAK;IACX,KAAK,CAAC,0BAA0B;CACxB,CAAC;AAIX,MAAM,UAAU,eAAe,CAAC,KAAgB;IAC9C,OAAO,aAAa,CAAC,OAAO,CAAC,KAA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,CAAC,IAAI,OAAO,GAAG,CAAC,kBAAkB,KAAK,QAAQ,CAAC;AAChG,CAAC;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,SAAS,SAAS,CAAkB,EAAQ,EAAE,CAAc;IAC1D,OAAO,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC;AACxB,CAAC","sourcesContent":["/** Change request types, states and state transitions. */\n\nimport type React from 'react';\nimport type { ProposalSet } from './proposal';\nimport { type RegisterStakeholder } from './stakeholder';\nimport type { RegisterItem } from './item';\n\n\n\nexport function isSubmittedBy(stakeholder: RegisterStakeholder, cr: Base): boolean {\n return (\n //isSubmitter(stakeholder) &&\n stakeholder.gitServerUsername === cr.submittingStakeholderGitServerUsername);\n}\n\n\n\n// =====================\n// Change request states\n// =====================\n\n/** Used in place of enum for convenience. */\nexport const State = {\n DRAFT: 'draft',\n PROPOSED: 'proposed',\n SUBMITTED_FOR_CONTROL_BODY_REVIEW: 'pending-control-body-review',\n RETURNED_FOR_CLARIFICATION: 'returned-for-clarification',\n WITHDRAWN: 'withdrawn',\n ACCEPTED: 'accepted',\n REJECTED: 'rejected',\n APPEALED: 'rejection-appealed-to-owner',\n ACCEPTED_ON_APPEAL: 'accepted-on-appeal',\n REJECTION_UPHELD_ON_APPEAL: 'rejection-upheld-on-appeal',\n APPEAL_WITHDRAWN: 'appeal-withdrawn',\n} as const;\n\nexport type StateType = typeof State[keyof typeof State];\n\nexport function isState(val: string): val is StateType {\n return Object.values(State).indexOf(val as StateType) >= 0;\n}\n\n/** A subset of `State` that represents editable states. */\nexport const EditableState = [\n State.DRAFT,\n State.RETURNED_FOR_CLARIFICATION,\n] as const;\n\nexport type EditableStateType = StateType & typeof EditableState[number];\n\nexport function isEditableState(state: StateType): state is EditableStateType {\n return EditableState.indexOf(state as EditableStateType) >= 0;\n}\n\n\n\n// ======================\n// Change request classes\n// ======================\n\n/**\n * Base change request type.\n *\n * Note that e.g. type Base<typeof State.DRAFT> does not equal to Drafted\n * because Drafted includes additional information (namely, SubmitterInput).\n *\n * If the state of a CR matters, this type should not be used directly\n * and concrete types should be used instead.\n */\nexport interface Base<S extends StateType = StateType>\n{\n id: string;\n // decision: typeof Decision[keyof typeof Decision]\n // disposition?: typeof Disposition[keyof typeof Disposition]\n state: S;\n\n /**\n * Used to match against stakeholders declared in register metadata.\n */\n submittingStakeholderGitServerUsername: string;\n\n items: ProposalSet;\n\n /**\n * Against to which register version changes were proposed.\n */\n registerVersion: string;\n\n /**\n * A link to external discussion.\n */\n externalDiscussionURI?: string;\n}\n\n\nexport function isCreatedBy(stakeholder: RegisterStakeholder, cr: Base): boolean {\n return stakeholder.gitServerUsername === cr.submittingStakeholderGitServerUsername;\n}\n\nexport function canBeEditedBy(stakeholder: RegisterStakeholder, cr: Base): boolean {\n return isCreatedBy(stakeholder, cr) && isEditableState(cr.state);\n}\n\n\n/** Proposal structure for single-file proposal import format. */\nexport interface ImportableCR {\n /** Proposal data. */\n proposalDraft: Drafted,\n /** Register item data for additions & clarifications. */\n itemPayloads: Record<string, RegisterItem<any>>,\n}\nexport function isImportableCR(val: any): val is ImportableCR {\n // TODO: More complete check\n return (\n val.proposalDraft.id\n && isDrafted(val.proposalDraft as Base)\n && Object.keys(val.itemPayloads).length > 0);\n}\n\n\n/**\n * A change request in any state.\n * Contains a superset of all possible properties, but all optional.\n * XXX: ^^^ This is a lie. Should be changed from | to & with Partial<>?\n */\nexport type SomeCR = \n | Drafted\n | Proposed\n | Withdrawn\n | ReturnedForClarificationByManager\n | SubmittedForControlBodyReview\n | ReturnedForClarificationByControlBody\n | Accepted\n | Rejected\n | RejectionUpheld\n | AcceptedOnAppeal\n | RejectedWithAppealWithdrawn;\n\nexport type Withdrawable =\n | Proposed\n | SubmittedForControlBodyReview\n | ReturnedForClarificationByManager\n | ReturnedForClarificationByControlBody;\n\nexport type Proposable =\n | Drafted\n | ReturnedForClarificationByManager\n | ReturnedForClarificationByControlBody;\n\nexport type SomeEditable =\n | Drafted\n | ReturnedForClarificationByManager\n | ReturnedForClarificationByControlBody;\n\nexport type Disposed =\n | Withdrawn\n | Accepted\n | Rejected\n | AcceptedOnAppeal\n | RejectionUpheld;\n\n\n// More specific change request types.\n// TODO: Refactor to avoid confusiong between current state e.g. Proposed)\n// and type (Proposed, to which all inheriting classes also conform)\n\nexport interface Drafted extends\n SubmitterInput,\n Base<typeof State.DRAFT> { timeStarted: Date, timeEdited: Date }\nexport function isDrafted(cr: Base): cr is Drafted {\n return isInState(cr, State.DRAFT);\n}\n\nexport interface Proposed extends\n Omit<Drafted, 'state'>,\n Base<typeof State.PROPOSED> { timeProposed: Date }\nexport function isProposed(cr: Base): cr is Proposed {\n return isInState(cr, State.PROPOSED);\n}\n\nexport interface Withdrawn extends\n Omit<Withdrawable, 'state'>,\n Base<typeof State.WITHDRAWN> { timeDisposed: Date }\nexport function isWithdrawn(cr: Base): cr is Withdrawn {\n return isInState(cr, State.WITHDRAWN);\n}\n\nexport function hadBeenProposed(cr: Base): cr is Base & { timeProposed: Date } {\n return cr && cr.hasOwnProperty('timeProposed') && !!(cr as Proposed).timeProposed;\n}\nexport function isDisposed(cr: Base): cr is Base & { timeDisposed: Date } {\n return cr && cr.hasOwnProperty('timeDisposed') && !!(cr as Disposed).timeDisposed;\n //return [\n // State.WITHDRAWN,\n // State.ACCEPTED,\n // State.REJECTED,\n // State.REJECTION_UPHELD_ON_APPEAL,\n // State.ACCEPTED_ON_APPEAL,\n //].some(s => cr.state === s);\n}\n\nexport interface SubmittedForControlBodyReview extends\n Omit<Proposed, 'state'>,\n RegisterManagerInput,\n Base<typeof State.SUBMITTED_FOR_CONTROL_BODY_REVIEW> {}\n\nexport interface ReturnedForClarificationByManager extends\n Omit<Proposed, 'state'>,\n RegisterManagerInput,\n Base<typeof State.RETURNED_FOR_CLARIFICATION> {}\n\nexport interface ReturnedForClarificationByControlBody extends\n Omit<SubmittedForControlBodyReview, 'state'>,\n ControlBodyInput,\n Base<typeof State.RETURNED_FOR_CLARIFICATION> {}\n\nexport interface Accepted extends\n Omit<SubmittedForControlBodyReview, 'state'>,\n ControlBodyInput,\n Base<typeof State.ACCEPTED> { timeDisposed: Date }\nexport function isAccepted(cr: Base): cr is Accepted {\n return isInState(cr, State.ACCEPTED);\n}\n\nexport interface Rejected extends\n Omit<SubmittedForControlBodyReview, 'state'>,\n ControlBodyInput,\n Base<typeof State.REJECTED> { timeDisposed: Date }\n\nexport interface Appealed extends\n Omit<Rejected, 'state' | 'timeDisposed'>,\n AppealRequest,\n Base<typeof State.APPEALED> { timeDisposed: undefined }\nexport function isAppealed(cr: Base): cr is Appealed {\n return isInState(cr, State.APPEALED);\n}\n\nexport interface RejectionUpheld extends\n Omit<Appealed, 'state' | 'timeDisposed'>,\n RegisterOwnerInput,\n Base<typeof State.REJECTION_UPHELD_ON_APPEAL> { timeDisposed: Date }\n\nexport interface AcceptedOnAppeal extends\n Omit<Appealed, 'state' | 'timeDisposed'>,\n RegisterOwnerInput,\n Base<typeof State.ACCEPTED_ON_APPEAL> { timeDisposed: Date }\nexport function isAcceptedOnAppeal(cr: Base): cr is AcceptedOnAppeal {\n return isInState(cr, State.ACCEPTED_ON_APPEAL);\n}\n\nexport interface RejectedWithAppealWithdrawn extends\n Omit<Appealed, 'state' | 'timeDisposed'>,\n Base<typeof State.APPEAL_WITHDRAWN> { timeDisposed: Date }\n\n\n\n// Input required when transitioning to different states\n\nexport interface SubmitterInput {\n justification: string;\n}\nexport function hasSubmitterInput(val: any): val is SubmitterInput {\n return val.hasOwnProperty('justification') && typeof val.justification === 'string';\n}\nexport interface RegisterManagerInput {\n registerManagerNotes: string;\n}\nexport function hasRegisterManagerInput(val: any): val is RegisterManagerInput {\n return val.hasOwnProperty('registerManagerNotes') && typeof val.registerManagerNotes === 'string';\n}\nexport interface ControlBodyInput {\n controlBodyNotes: string;\n}\nexport function hasControlBodyInput(val: any): val is ControlBodyInput {\n return (\n val.hasOwnProperty('controlBodyNotes') && typeof val.controlBodyNotes === 'string' &&\n val.hasOwnProperty('controlBodyDecisionEvent') && typeof val.controlBodyDecisionEvent === 'string');\n}\nexport interface AppealRequest {\n appealReason: string;\n}\nexport function hasAppealRequest(val: any): val is AppealRequest {\n return val.hasOwnProperty('appealReason') && typeof val.appealReason === 'string';\n}\nexport interface RegisterOwnerInput {\n registerOwnerNotes: string;\n}\nexport function hasRegisterOwnerInput(val: any): val is RegisterOwnerInput {\n return val.hasOwnProperty('registerOwnerNotes') && typeof val.registerOwnerNotes === 'string';\n}\n\nexport type StateInput =\n | SubmitterInput\n | RegisterManagerInput\n | ControlBodyInput\n | AppealRequest\n | RegisterOwnerInput;\n\n\n/** \n * CR type guard helper.\n * Normally you would not use it directly and instead use\n * more specific is[Type]() helper from this module.\n *\n * Checks CR type using the `state` property.\n * Does not validate other properties.\n *\n * Usage:\n *\n * @example\n * ```ts\n * let someCR;\n * if (isInState<Drafted>(someCR, State.DRAFT)) {\n * // Can assume someCR is Drafted\n * }\n * ```\n *\n * It’ll try to tell you if you mismatch those.\n *\n * @example\n * Will not compile:\n * ```ts\n * let someCR;\n * if (isInState<Drafted>(someCR, State.PROPOSED)) {\n * // Compile error\n * // because State.PROPOSED is not a possible value of Drafted[\"state\"]\n * }\n * ```\n *\n * @example\n * Incorrect usage (do not do this):\n * ```ts\n * let someCR;\n * if (isInState(someCR, State.DRAFT)) {\n * // Can NOT assume someCR is Drafted\n * // The compiler must know the expected concrete CR type\n * }\n * ```\n */\nfunction isInState<CR extends Base>(cr: Base, s: CR[\"state\"]): cr is CR {\n return cr.state === s;\n}\n\n\n\n\n// ===========\n// Transitions\n// ===========\n\n/**\n * A function that transitions CR1 to CR2.\n *\n * The function is declared to return the object\n * without the `state` field, it is set\n * by common wrapper function to reduce duplication.\n */\nexport type Transition<\n /** From CR of this subtype */\n CR1 extends Base,\n /** To CR of this subtype */\n CR2 extends Base,\n /** Using this extra information */\n P extends Record<string, any> | null = null,\n> = (cr: CR1, payload: P) => Omit<CR2, 'state'>;\n\n\n/**\n * Describes a transition.\n *\n * @typeParam CR1: Change request source state type\n * @typeParam CR2: Change request target state type\n * @typeParam P: Extra input needed to transition, if any\n */\nexport interface TransitionConfig<CR1 extends Base, CR2 extends Base, P extends Record<string, any> | null = null> {\n /**\n * Function that implements the transition.\n * Takes a CR in the original state and returns CR in the new state.\n * Additionally, takes appropriate payload, if any, for the transition\n * (e.g., register manager or control body notes).\n *\n * For function implementor:\n *\n * - Function MUST NOT modify CR in place.\n * - Function should throw if submitted payload does not conform to requirements.\n */\n func: Transition<CR1, CR2, P>;\n\n targetState: CR2[\"state\"];\n\n /** Title. Use verb. */\n title: string;\n\n hint?: string | JSX.Element;\n\n /** Widget that can be used to view or enter extra input. */\n Widget: P extends null ? null : React.FC<{ value: P, onChange?: (userInput: P) => void }>;\n\n /**\n * Function that returns true\n * if given stakeholder can perform this transition on given CR.\n */\n canBeTransitionedBy: (stakeholder: RegisterStakeholder, cr: CR1) => boolean;\n}\n\n\n// type TransitionSpec = {\n// [S1 in StateType]?: {\n// [S2 in StateType]?: Transition<Base<S1>, Base<S2>, Record<string, any>>\n// }\n// }\n\n\n/**\n * Source of truth for available transitions.\n * When updating change request business logic,\n * this is the type that should be modified.\n *\n * It will cause compile errors until transition implementation\n * is updated correspondingly.\n */\nexport type Transitions = {\n [State.DRAFT]: {\n // [State.DRAFT]:\n // TransitionConfig<Drafted, Drafted, SubmitterInput>;\n [State.WITHDRAWN]:\n TransitionConfig<Proposed, Withdrawn>;\n [State.PROPOSED]:\n TransitionConfig<Drafted, Proposed, SubmitterInput>;\n };\n [State.PROPOSED]: {\n [State.WITHDRAWN]:\n TransitionConfig<Proposed, Withdrawn>;\n [State.SUBMITTED_FOR_CONTROL_BODY_REVIEW]:\n TransitionConfig<Proposed, SubmittedForControlBodyReview, RegisterManagerInput>;\n [State.RETURNED_FOR_CLARIFICATION]:\n TransitionConfig<Proposed, ReturnedForClarificationByManager, RegisterManagerInput>;\n };\n [State.SUBMITTED_FOR_CONTROL_BODY_REVIEW]: {\n [State.WITHDRAWN]:\n TransitionConfig<SubmittedForControlBodyReview, Withdrawn>;\n [State.RETURNED_FOR_CLARIFICATION]:\n TransitionConfig<SubmittedForControlBodyReview, ReturnedForClarificationByControlBody, ControlBodyInput>;\n [State.REJECTED]:\n TransitionConfig<SubmittedForControlBodyReview, Rejected, ControlBodyInput>;\n [State.ACCEPTED]:\n TransitionConfig<SubmittedForControlBodyReview, Accepted, ControlBodyInput>;\n };\n [State.RETURNED_FOR_CLARIFICATION]: {\n [State.PROPOSED]:\n TransitionConfig<ReturnedForClarificationByManager | ReturnedForClarificationByControlBody, Proposed, SubmitterInput>;\n [State.WITHDRAWN]:\n TransitionConfig<ReturnedForClarificationByManager | ReturnedForClarificationByControlBody, Withdrawn>;\n };\n [State.REJECTED]: {\n [State.APPEALED]:\n TransitionConfig<Rejected, Appealed, AppealRequest>;\n };\n [State.APPEALED]: {\n [State.APPEAL_WITHDRAWN]:\n TransitionConfig<Appealed, RejectedWithAppealWithdrawn>;\n [State.ACCEPTED_ON_APPEAL]:\n TransitionConfig<Appealed, AcceptedOnAppeal, RegisterOwnerInput>;\n [State.REJECTION_UPHELD_ON_APPEAL]:\n TransitionConfig<Appealed, RejectionUpheld, RegisterOwnerInput>;\n };\n}\n"]}
@@ -13,7 +13,11 @@ export declare const DISPOSITION_OPTIONS: readonly ["withdrawn", "accepted", "no
13
13
  export declare type ProposalSet = {
14
14
  [objectPath: string]: ChangeProposal;
15
15
  };
16
- /** A change request, per ISO 19135-1 model. */
16
+ /**
17
+ * A change request, per ISO 19135-1 model.
18
+ *
19
+ * @deprecated use cr.Base (or a more specific type) instead
20
+ */
17
21
  export interface ChangeRequest {
18
22
  /** Justification for the change */
19
23
  justification: string;
@@ -1 +1 @@
1
- {"version":3,"file":"proposal.js","sourceRoot":"","sources":["../../src/types/proposal.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,SAAS;IACT,WAAW;IACX,OAAO;CACC,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,WAAW;IACX,UAAU;IACV,aAAa;CACL,CAAC;AA6CX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,eAAe;IACf,WAAW;CACH,CAAC;AAqBX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc;IACd,YAAY;IACZ,cAAc;CACN,CAAC","sourcesContent":["import type { RegisterStakeholder } from './stakeholder';\nimport type { Citation } from './util';\n\n\nexport const DECISION_STATUSES = [\n 'pending',\n 'tentative',\n 'final',\n] as const;\n\nexport const DISPOSITION_OPTIONS = [\n 'withdrawn',\n 'accepted',\n 'notAccepted',\n] as const;\n\n/**\n * Item paths in proposal set must start with a slash\n * and will be treated relative to dataset root.\n * Object paths should conform to registry item path shape\n * of `/<classID>/<itemID>.yaml`.\n * (the `[/subregisterID]/<classID>/<itemID>.yaml` is acceptable\n * but deprecated, as subregisters are deprecated).\n */\nexport type ProposalSet = {\n [objectPath: string]: ChangeProposal\n}\n\n/** A change request, per ISO 19135-1 model. */\nexport interface ChangeRequest {\n // Supplied by sponsor\n /** Justification for the change */\n justification: string\n\n proposals: ProposalSet\n\n // Enforced by the system\n id: string\n timeStarted: Date\n timeProposed?: Date\n timeDisposed?: Date\n sponsor: RegisterStakeholder\n\n // Supplied by register manager\n status: typeof DECISION_STATUSES[number] // Default filled in by the system but changeable\n disposition?: typeof DISPOSITION_OPTIONS[number]\n controlBodyDecisionEvent?: string\n controlBodyNotes?: string\n registerManagerNotes?: string\n}\n\n\n/**\n * Change request properties for the purposes of drafting.\n * (`controlBodyNotes` is in question.)\n */\nexport type DraftChangeRequest =\n Pick<ChangeRequest, 'proposals' | 'justification' | 'controlBodyNotes' | 'sponsor'>;\n\nexport const PROPOSAL_TYPES = [\n 'addition',\n 'clarification',\n 'amendment',\n] as const;\n\ninterface BaseProposal {\n //itemID: RegisterItemID\n disposition?: 'accepted' | 'notAccepted'\n type: typeof PROPOSAL_TYPES[number]\n sources?: Citation[]\n}\n\nexport interface Addition extends BaseProposal {\n type: 'addition'\n ///** New item data. */\n //payload: Payload\n}\n\nexport interface Clarification extends BaseProposal {\n type: 'clarification'\n ///** Updated item data */\n //payload: Payload\n}\n\nexport const AMENDMENT_TYPES = [\n 'supersession',\n 'retirement',\n 'invalidation',\n] as const;\ninterface BaseAmendment extends BaseProposal {\n type: 'amendment'\n amendmentType: typeof AMENDMENT_TYPES[number]\n}\nexport interface Retirement extends BaseAmendment {\n amendmentType: 'retirement'\n}\nexport interface Supersession extends BaseAmendment {\n amendmentType: 'supersession'\n supersedingItemIDs: string[]\n}\nexport interface Invalidation extends BaseAmendment {\n amendmentType: 'invalidation'\n}\nexport type Amendment = Supersession | Retirement | Invalidation\n\nexport type ChangeProposal = Amendment | Clarification | Addition\n"]}
1
+ {"version":3,"file":"proposal.js","sourceRoot":"","sources":["../../src/types/proposal.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,SAAS;IACT,WAAW;IACX,OAAO;CACC,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,WAAW;IACX,UAAU;IACV,aAAa;CACL,CAAC;AAiDX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,eAAe;IACf,WAAW;CACH,CAAC;AAqBX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc;IACd,YAAY;IACZ,cAAc;CACN,CAAC","sourcesContent":["import type { RegisterStakeholder } from './stakeholder';\nimport type { Citation } from './util';\n\n\nexport const DECISION_STATUSES = [\n 'pending',\n 'tentative',\n 'final',\n] as const;\n\nexport const DISPOSITION_OPTIONS = [\n 'withdrawn',\n 'accepted',\n 'notAccepted',\n] as const;\n\n/**\n * Item paths in proposal set must start with a slash\n * and will be treated relative to dataset root.\n * Object paths should conform to registry item path shape\n * of `/<classID>/<itemID>.yaml`.\n * (the `[/subregisterID]/<classID>/<itemID>.yaml` is acceptable\n * but deprecated, as subregisters are deprecated).\n */\nexport type ProposalSet = {\n [objectPath: string]: ChangeProposal\n}\n\n/**\n * A change request, per ISO 19135-1 model.\n *\n * @deprecated use cr.Base (or a more specific type) instead\n */\nexport interface ChangeRequest {\n // Supplied by sponsor\n /** Justification for the change */\n justification: string\n\n proposals: ProposalSet\n\n // Enforced by the system\n id: string\n timeStarted: Date\n timeProposed?: Date\n timeDisposed?: Date\n sponsor: RegisterStakeholder\n\n // Supplied by register manager\n status: typeof DECISION_STATUSES[number] // Default filled in by the system but changeable\n disposition?: typeof DISPOSITION_OPTIONS[number]\n controlBodyDecisionEvent?: string\n controlBodyNotes?: string\n registerManagerNotes?: string\n}\n\n\n/**\n * Change request properties for the purposes of drafting.\n * (`controlBodyNotes` is in question.)\n */\nexport type DraftChangeRequest =\n Pick<ChangeRequest, 'proposals' | 'justification' | 'controlBodyNotes' | 'sponsor'>;\n\nexport const PROPOSAL_TYPES = [\n 'addition',\n 'clarification',\n 'amendment',\n] as const;\n\ninterface BaseProposal {\n //itemID: RegisterItemID\n disposition?: 'accepted' | 'notAccepted'\n type: typeof PROPOSAL_TYPES[number]\n sources?: Citation[]\n}\n\nexport interface Addition extends BaseProposal {\n type: 'addition'\n ///** New item data. */\n //payload: Payload\n}\n\nexport interface Clarification extends BaseProposal {\n type: 'clarification'\n ///** Updated item data */\n //payload: Payload\n}\n\nexport const AMENDMENT_TYPES = [\n 'supersession',\n 'retirement',\n 'invalidation',\n] as const;\ninterface BaseAmendment extends BaseProposal {\n type: 'amendment'\n amendmentType: typeof AMENDMENT_TYPES[number]\n}\nexport interface Retirement extends BaseAmendment {\n amendmentType: 'retirement'\n}\nexport interface Supersession extends BaseAmendment {\n amendmentType: 'supersession'\n supersedingItemIDs: string[]\n}\nexport interface Invalidation extends BaseAmendment {\n amendmentType: 'invalidation'\n}\nexport type Amendment = Supersession | Retirement | Invalidation\n\nexport type ChangeProposal = Amendment | Clarification | Addition\n"]}
@@ -1,9 +1,45 @@
1
- import type { ObjectChangeset } from '@riboseinc/paneron-extension-kit/types/objects';
2
- import type { RegisterItem, ChangeRequest, ChangeProposal } from '../../types';
1
+ import type { ObjectDataset, ObjectChangeset } from '@riboseinc/paneron-extension-kit/types/objects';
2
+ import type { RegisterItem, ProposalSet, ChangeProposal, ItemClassConfigurationSet } from '../../types';
3
3
  import type { Version as RegisterVersion } from '../../types/register';
4
- import { type Drafted, type ReturnedForClarificationByManager, type ReturnedForClarificationByControlBody } from '../../types/cr';
4
+ import { type Drafted, type ReturnedForClarificationByManager, type ReturnedForClarificationByControlBody, ImportableCR } from '../../types/cr';
5
5
  /** Takes a justification and ID, returns an object changeset. */
6
6
  export declare function newCRObjectChangeset(id: string, justification: string, registerVersion: RegisterVersion, stakeholderGitServerUsername: string): ObjectChangeset;
7
+ /**
8
+ * Returns an object changeset given an importable proposal,
9
+ * item class definitions for register to import it to,
10
+ * and a function to fetch register item data.
11
+ *
12
+ * Throws an error if importable proposal data isn’t compatible
13
+ * with item class definitions or existing register data.
14
+ */
15
+ export declare function importedProposalToCRObjectChangeset(importableCR: ImportableCR,
16
+ /** Available item classes per register configuration. */
17
+ itemClasses: ItemClassConfigurationSet, getObjectData: (opts: {
18
+ objectPaths: string[];
19
+ }) => Promise<{
20
+ data: ObjectDataset;
21
+ }>, findObjects: (predicate: string) => Promise<any[]>): Promise<ObjectChangeset>;
22
+ /**
23
+ * When importable CR wants to link to preexisting register items,
24
+ * and it does not know their exact UUIDs but knows some other properties,
25
+ * it can provide this structure in place of a reference.
26
+ *
27
+ * `resolvePredicates()` will resolve any such placeholders to item UUIDs
28
+ * at import time.
29
+ *
30
+ * `mode` should specify whether the predicate should be replaced with
31
+ * only a UUID string ('id', if classID is already known)
32
+ * or full InternalItemReference ('generic').
33
+ */
34
+ export interface Predicate {
35
+ __isPredicate: true;
36
+ /**
37
+ * Predicate expression to resolve.
38
+ * Example: `data.identifier && parseInt(data.identifier, 10) === 123`.
39
+ */
40
+ predicate: string;
41
+ mode: 'generic' | 'id';
42
+ }
7
43
  /**
8
44
  * Returns an object changeset to update CR with new given proposal items.
9
45
  * Only applicable to CR at draft edit stage.
@@ -28,4 +64,4 @@ itemData?: Record<string, RegisterItem<any>>): ObjectChangeset;
28
64
  * Given change proposals, returns applicable changes
29
65
  * to objects in the dataset.
30
66
  */
31
- export declare function proposalsToObjectChangeset(crID: string, hasSubregisters: boolean, proposals: ChangeRequest["proposals"], itemData: Record<string, RegisterItem<any> | null>, newItemData: Record<string, RegisterItem<any> | null>): Promise<ObjectChangeset>;
67
+ export declare function proposalsToObjectChangeset(crID: string, hasSubregisters: boolean, proposals: ProposalSet, itemData: Record<string, RegisterItem<any> | null>, newItemData: Record<string, RegisterItem<any> | null>): Promise<ObjectChangeset>;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.newCRObjectChangeset = newCRObjectChangeset;
7
+ exports.importedProposalToCRObjectChangeset = importedProposalToCRObjectChangeset;
7
8
  exports.updateCRObjectChangeset = updateCRObjectChangeset;
8
9
  exports.proposalsToObjectChangeset = proposalsToObjectChangeset;
9
10
 
@@ -34,6 +35,117 @@ function newCRObjectChangeset(id, justification, registerVersion, stakeholderGit
34
35
  }
35
36
  };
36
37
  }
38
+ /**
39
+ * Returns an object changeset given an importable proposal,
40
+ * item class definitions for register to import it to,
41
+ * and a function to fetch register item data.
42
+ *
43
+ * Throws an error if importable proposal data isn’t compatible
44
+ * with item class definitions or existing register data.
45
+ */
46
+
47
+
48
+ async function importedProposalToCRObjectChangeset(importableCR,
49
+ /** Available item classes per register configuration. */
50
+ itemClasses, getObjectData, findObjects) {
51
+ var _a;
52
+
53
+ const proposalDraft = importableCR.proposalDraft;
54
+ const crID = proposalDraft.id;
55
+ const crPath = (0, _itemPathUtils.crIDToCRPath)(crID);
56
+ const itemPaths = Object.keys(proposalDraft.items);
57
+ const proposals = Object.values(proposalDraft.items);
58
+
59
+ for (const itemPath of itemPaths) {
60
+ const itemRef = (0, _itemPathUtils.itemPathToItemRef)(false, itemPath);
61
+
62
+ if (!itemClasses[itemRef.classID]) {
63
+ throw new Error(`Imported proposal contains item(s) of unknown class ${itemRef.classID}`);
64
+ }
65
+ }
66
+
67
+ if (proposals.find(prop => prop.type !== 'addition')) {
68
+ throw new Error("Only addition proposals can be imported at this time");
69
+ }
70
+
71
+ const existingItems = (await getObjectData({
72
+ objectPaths: itemPaths
73
+ })).data;
74
+
75
+ if (Object.values(existingItems).find(v => v !== null)) {
76
+ throw new Error("Register already contains item(s) in this proposal");
77
+ }
78
+
79
+ const changeset = {
80
+ [crPath]: {
81
+ oldValue: null,
82
+ newValue: proposalDraft
83
+ }
84
+ };
85
+
86
+ for (const [itemPath, itemPayload] of Object.entries((_a = importableCR.itemPayloads) !== null && _a !== void 0 ? _a : {})) {
87
+ if (itemPaths.indexOf(itemPath) < 0) {
88
+ throw new Error(`No proposal found for item at ${itemPath}, but item data is given`);
89
+ }
90
+
91
+ if (!(0, _types.isRegisterItem)(itemPayload)) {
92
+ throw new Error(`Invalid register item data at ${itemPath}`);
93
+ }
94
+
95
+ changeset[(0, _itemPathUtils.itemPathInCR)(itemPath, crID)] = {
96
+ oldValue: null,
97
+ newValue: await resolvePredicates(itemPayload, async function resolveRef(predicate) {
98
+ const objects = (await findObjects(predicate)).filter(o => o.objectPath === (0, _itemPathUtils.itemPathNotInCR)(o.objectPath));
99
+
100
+ if (objects.length < 1) {
101
+ throw new Error(`Unable to resolve predicate to item UUID: no item found matching ${predicate}`);
102
+ } else if (objects.length > 1) {
103
+ const objectOverview = objects.map(o => JSON.stringify(o)).join(', ');
104
+ throw new Error(`Unable to resolve predicate to item UUID: more than one item matches ${predicate}: ${objectOverview}`);
105
+ } else {
106
+ return (0, _itemPathUtils.itemPathToItemRef)(false, objects[0].objectPath);
107
+ }
108
+ })
109
+ };
110
+ }
111
+
112
+ return changeset;
113
+ }
114
+
115
+ function isPredicate(val) {
116
+ return val && val.__isPredicate === true;
117
+ }
118
+ /**
119
+ * Resolves any properties that should reference register item UUIDs,
120
+ * but have predicates instead.
121
+ */
122
+
123
+
124
+ async function resolvePredicates(value, resolveRef) {
125
+ // NOTE: Return types are cast because https://github.com/microsoft/TypeScript/issues/33912.
126
+ if (isPredicate(value)) {
127
+ const ref = await resolveRef(value.predicate);
128
+
129
+ if (value.mode === 'generic') {
130
+ return ref;
131
+ } else {
132
+ return ref.itemID;
133
+ }
134
+ } else if (value && typeof value === 'object') {
135
+ if (Array.isArray(value)) {
136
+ return await Promise.all(value.map(v => resolvePredicates(v, resolveRef)));
137
+ } else {
138
+ // Assume plain non-array object.
139
+ for (const [key, v] of Object.entries(value)) {
140
+ value[key] = await resolvePredicates(v, resolveRef);
141
+ }
142
+
143
+ return value;
144
+ }
145
+ } else {
146
+ return value;
147
+ }
148
+ }
37
149
  /**
38
150
  * Returns an object changeset to update CR with new given proposal items.
39
151
  * Only applicable to CR at draft edit stage.
@@ -1 +1 @@
1
- {"version":3,"file":"objectChangeset.js","sourceRoot":"","sources":["../../../src/views/change-request/objectChangeset.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACL,KAAK,GAIN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGpG,iEAAiE;AACjE,MAAM,UAAU,oBAAoB,CAClC,EAAU,EACV,aAAqB,EACrB,eAAgC,EAChC,4BAAoC;IAGpC,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,EAAE,GAAY;QAClB,EAAE;QACF,WAAW;QACX,UAAU,EAAE,WAAW;QACvB,aAAa;QACb,sCAAsC,EAAE,4BAA4B;QACpE,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,eAAe,EAAE,eAAgB,CAAC,EAAE;KACrC,CAAC;IACF,MAAM,YAA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AK,CAAC,kEAAkE,CAAC,CAAC;SACrF;QACD,WAAW,GAAG;YACZ,EAAE,EAAE,OAAO,CAAC,MAAM;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,IAAI,IAAI,EAAE;SACzB,CAAC;KACH;IAED,SAAS,CAAC,QAAQ,CAAC,GAAG;QACpB,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,WAAW;KACtB,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { Change, Changeset } from '@riboseinc/paneron-extension-kit/types/changes';\nimport type { ObjectChangeset } from '@riboseinc/paneron-extension-kit/types/objects';\nimport type {\n InternalItemReference,\n RegisterItem,\n ChangeRequest,\n ChangeProposal,\n Amendment,\n Supersession,\n} from '../../types';\nimport { isRegisterItem } from '../../types';\nimport type { Version as RegisterVersion } from '../../types/register';\nimport {\n State,\n type Drafted,\n type ReturnedForClarificationByManager,\n type ReturnedForClarificationByControlBody,\n} from '../../types/cr';\nimport { crIDToCRPath, itemPathInCR, itemPathToItemRef, itemRefToItemPath } from '../itemPathUtils';\n\n\n/** Takes a justification and ID, returns an object changeset. */\nexport function newCRObjectChangeset(\n id: string,\n justification: string,\n registerVersion: RegisterVersion,\n stakeholderGitServerUsername: string,\n): ObjectChangeset {\n\n const timeStarted = new Date();\n const cr: Drafted = {\n id,\n timeStarted,\n timeEdited: timeStarted,\n justification,\n submittingStakeholderGitServerUsername: stakeholderGitServerUsername,\n items: {},\n state: State.DRAFT,\n registerVersion: registerVersion!.id,\n };\n const crObjectPath = crIDToCRPath(id);\n return {\n [crObjectPath]: {\n oldValue: null,\n newValue: cr,\n },\n }\n}\n\n\n/**\n * Returns an object changeset to update CR with new given proposal items.\n * Only applicable to CR at draft edit stage.\n */\nexport function updateCRObjectChangeset(\n /**\n * Change request data.\n */\n cr: Drafted | ReturnedForClarificationByManager | ReturnedForClarificationByControlBody,\n\n /**\n * Proposals by item path.\n * Will be merged with those already existing in `cr`.\n * If a proposal is undefined, it will be removed.\n */\n proposalItems: Record<string, ChangeProposal | null>,\n\n /**\n * New item data must be provided for additions and clarifications,\n * keyed by item path.\n */\n itemData: Record<string, RegisterItem<any>> = {},\n): ObjectChangeset {\n const changeset: ObjectChangeset = {};\n const newItems = { ...cr.items };\n for (const [itemPath, proposal] of Object.entries(proposalItems)) {\n // Update proposals on CR\n if (proposal !== null) {\n newItems[itemPath] = proposal;\n } else if (newItems[itemPath]) {\n delete newItems[itemPath];\n }\n // Add/remove item data\n if (proposal?.type === 'addition' || proposal?.type === 'clarification') {\n const proposedItemData = itemData[itemPath];\n if (proposedItemData === null || !isRegisterItem(proposedItemData)) {\n console.error(\"Unable to convert proposals to object changeset: original item data is missing\", itemPath);\n throw new Error(\"Unable to convert proposals to object changeset: original item data is missing\");\n }\n changeset[itemPathInCR(itemPath, cr.id)] = {\n // When editing a draft, we don’t care\n // about overwriting proposed item data so we omit oldValue.\n newValue: proposedItemData,\n };\n } else {\n changeset[itemPathInCR(itemPath, cr.id)] = {\n // When editing a draft, we don’t care\n // about overwriting proposed item data so we omit oldValue.\n newValue: null,\n };\n }\n }\n // Update main CR data\n const crPath = crIDToCRPath(cr.id);\n changeset[crPath] = {\n oldValue: cr,\n newValue: { ...cr, items: newItems, timeEdited: new Date() },\n };\n return changeset;\n}\n\n\n/**\n * Given change proposals, returns applicable changes\n * to objects in the dataset.\n */\nexport async function proposalsToObjectChangeset(\n crID: string,\n hasSubregisters: boolean,\n proposals: ChangeRequest[\"proposals\"],\n itemData: Record<string, RegisterItem<any> | null>,\n newItemData: Record<string, RegisterItem<any> | null>,\n): Promise<ObjectChangeset> {\n const cs: ObjectChangeset = {};\n\n for (const [itemPath, proposal] of Object.entries(proposals)) {\n //const originalItem: RegisterItem<any> | undefined = (itemData[itemPath] ?? undefined);\n const itemRef = itemPathToItemRef(hasSubregisters, itemPath);\n\n if (proposal.type !== 'addition') {\n if (itemData[itemPath] === undefined) {\n console.error(\"Unable to convert proposals to object changeset: original item data is missing\", itemPath);\n throw new Error(\"Unable to convert proposals to object changeset: original item data is missing\");\n }\n if (proposal.type === 'amendment' && proposal.amendmentType === 'supersession') {\n Object.assign(cs, await proposalToObjectChangeset(crID, proposal, itemRef, itemPath, itemData, newItemData));\n } else {\n Object.assign(cs, await proposalToObjectChangeset(crID, proposal, itemRef, itemPath, itemData, newItemData));\n }\n } else {\n Object.assign(cs, await proposalToObjectChangeset(crID, proposal, itemRef, itemPath, itemData, newItemData));\n }\n }\n\n return cs;\n}\n\n// TODO: Refactor out the business logic of proposal approval.\n/**\n * Given a change proposal, returns applicable changes\n * to objects in the dataset.\n * Core logic of approving a proposal.\n * Takes a proposal and extra options (depending on proposal type).\n * Returns a Changeset containing register items at appropriate paths.\n */\nasync function proposalToObjectChangeset(\n crID: string,\n proposal: ChangeProposal,\n itemRef: InternalItemReference,\n itemPath: string,\n itemData: Record<string, RegisterItem<any> | null>,\n newItemData: Record<string, RegisterItem<any> | null>,\n): Promise<Changeset<Change<RegisterItem<any>>>> {\n let updatedItem: RegisterItem<any>;\n const changeset: Changeset<Change<RegisterItem<any>>> = {};\n\n const origItem = itemData[itemPath] ?? null;\n const newItem = newItemData[itemPathInCR(itemPath, crID)] ?? null;\n\n if (proposal.type !== 'addition') {\n if (origItem === null) {\n throw new Error(\"proposalToObjectChangeset() requires original item data for non-additions\");\n }\n\n updatedItem = { ...origItem };\n\n switch (proposal.type) {\n case 'clarification':\n if (newItem === null) {\n throw new Error(\"proposalToObjectChangeset() requires new item data for clarifications\");\n }\n //const clarification = proposal as Clarification;\n updatedItem.data = newItem.data //clarification.payload;\n break;\n case 'amendment':\n const amendment = proposal as Amendment;\n updatedItem.amendedInCR = crID;\n\n switch (amendment.amendmentType) {\n case 'retirement':\n updatedItem.status = 'retired';\n break;\n case 'invalidation':\n updatedItem.status = 'invalid';\n break;\n case 'supersession':\n const supersession = proposal as Supersession;\n updatedItem.status = 'superseded';\n updatedItem.supersededBy = supersession.supersedingItemIDs.map(itemID => ({\n itemID,\n classID: itemRef.classID,\n subregisterID: itemRef.subregisterID,\n }));\n for (const supersedingItemPath of updatedItem.supersededBy.map(ip => itemRefToItemPath(ip))) {\n const supersedingItemData = itemData[supersedingItemPath];\n if (supersedingItemData) {\n changeset[supersedingItemPath] = {\n oldValue: supersedingItemData,\n newValue: {\n ...supersedingItemData,\n supersedes: [ ...(supersedingItemData.supersedes ?? []), itemRef ],\n },\n };\n }\n }\n break;\n }\n break;\n }\n } else {\n if (newItem === null) {\n throw new Error(\"proposalToObjectChangeset() requires new item data for additions\");\n }\n updatedItem = {\n id: itemRef.itemID,\n data: newItem.data,\n status: 'valid',\n dateAccepted: new Date(),\n };\n }\n\n changeset[itemPath] = {\n oldValue: origItem,\n newValue: updatedItem,\n };\n\n return changeset;\n}\n"]}
1
+ {"version":3,"file":"objectChangeset.js","sourceRoot":"","sources":["../../../src/views/change-request/objectChangeset.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACL,KAAK,GAKN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,iEAAiE;AACjE,MAAM,UAAU,oBAAoB,CAClC,EAAU,EACV,aAAqB,EACrB,eAAgC,EAChC,4BAAoC;IAGpC,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,EAAE,GAAY;QAClB,EAAE;QACF,WAAW;QACX,UAAU,EAAE,WAAW;QACvB,aAAa;QACb,sCAAsC,EAAE,4BAA4B;QACpE,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,eAAe,EAAE,eAAgB,CAAC,EAAE;KACrC,CAAC;IACF,MAAM,YAAY,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IACtC,OAAO;QACL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AE,IAAI,IAAI,EAAE;SACzB,CAAC;KACH;IAED,SAAS,CAAC,QAAQ,CAAC,GAAG;QACpB,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,WAAW;KACtB,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { Change, Changeset } from '@riboseinc/paneron-extension-kit/types/changes';\nimport type { ObjectDataset, ObjectChangeset } from '@riboseinc/paneron-extension-kit/types/objects';\nimport type {\n InternalItemReference,\n RegisterItem,\n ProposalSet,\n ChangeProposal,\n Amendment,\n Supersession,\n ItemClassConfigurationSet,\n} from '../../types';\nimport { isRegisterItem } from '../../types';\nimport type { Version as RegisterVersion } from '../../types/register';\nimport {\n State,\n type Drafted,\n type ReturnedForClarificationByManager,\n type ReturnedForClarificationByControlBody,\n ImportableCR,\n} from '../../types/cr';\nimport {\n crIDToCRPath,\n itemPathInCR,\n itemPathNotInCR,\n itemPathToItemRef,\n itemRefToItemPath,\n} from '../itemPathUtils';\n\n\n/** Takes a justification and ID, returns an object changeset. */\nexport function newCRObjectChangeset(\n id: string,\n justification: string,\n registerVersion: RegisterVersion,\n stakeholderGitServerUsername: string,\n): ObjectChangeset {\n\n const timeStarted = new Date();\n const cr: Drafted = {\n id,\n timeStarted,\n timeEdited: timeStarted,\n justification,\n submittingStakeholderGitServerUsername: stakeholderGitServerUsername,\n items: {},\n state: State.DRAFT,\n registerVersion: registerVersion!.id,\n };\n const crObjectPath = crIDToCRPath(id);\n return {\n [crObjectPath]: {\n oldValue: null,\n newValue: cr,\n },\n }\n}\n\n\n/**\n * Returns an object changeset given an importable proposal,\n * item class definitions for register to import it to,\n * and a function to fetch register item data.\n *\n * Throws an error if importable proposal data isn’t compatible\n * with item class definitions or existing register data.\n */\nexport async function importedProposalToCRObjectChangeset(\n importableCR: ImportableCR,\n /** Available item classes per register configuration. */\n itemClasses: ItemClassConfigurationSet,\n getObjectData: (opts: { objectPaths: string[] }) => Promise<{ data: ObjectDataset }>,\n findObjects: (predicate: string) => Promise<any[]>,\n): Promise<ObjectChangeset> {\n const proposalDraft: Drafted = importableCR.proposalDraft;\n const crID = proposalDraft.id;\n const crPath = crIDToCRPath(crID);\n\n const itemPaths = Object.keys(proposalDraft.items);\n const proposals = Object.values(proposalDraft.items);\n\n for (const itemPath of itemPaths) {\n const itemRef = itemPathToItemRef(false, itemPath);\n if (!itemClasses[itemRef.classID]) {\n throw new Error(`Imported proposal contains item(s) of unknown class ${itemRef.classID}`);\n }\n }\n\n if (proposals.find(prop => prop.type !== 'addition')) {\n throw new Error(\"Only addition proposals can be imported at this time\");\n }\n\n const existingItems = (await getObjectData({ objectPaths: itemPaths })).data;\n if (Object.values(existingItems).find(v => v !== null)) {\n throw new Error(\"Register already contains item(s) in this proposal\");\n }\n\n const changeset: ObjectChangeset = {\n [crPath]: {\n oldValue: null,\n newValue: proposalDraft,\n },\n };\n\n for (const [itemPath, itemPayload] of Object.entries(importableCR.itemPayloads ?? {})) {\n if (itemPaths.indexOf(itemPath) < 0) {\n throw new Error(`No proposal found for item at ${itemPath}, but item data is given`);\n }\n if (!isRegisterItem(itemPayload)) {\n throw new Error(`Invalid register item data at ${itemPath}`);\n }\n changeset[itemPathInCR(itemPath, crID)] = {\n oldValue: null,\n newValue: await resolvePredicates(itemPayload, async function resolveRef(predicate: string) {\n const objects = (await findObjects(predicate)).\n filter((o: any) => o.objectPath === itemPathNotInCR(o.objectPath));\n if (objects.length < 1) {\n throw new Error(`Unable to resolve predicate to item UUID: no item found matching ${predicate}`);\n } else if (objects.length > 1) {\n const objectOverview = objects.map((o: any) => JSON.stringify(o)).join(', ')\n throw new Error(`Unable to resolve predicate to item UUID: more than one item matches ${predicate}: ${objectOverview}`);\n } else {\n return itemPathToItemRef(false, objects[0].objectPath);\n }\n }),\n };\n }\n\n return changeset;\n}\n\n\n/**\n * When importable CR wants to link to preexisting register items,\n * and it does not know their exact UUIDs but knows some other properties,\n * it can provide this structure in place of a reference.\n *\n * `resolvePredicates()` will resolve any such placeholders to item UUIDs\n * at import time.\n *\n * `mode` should specify whether the predicate should be replaced with\n * only a UUID string ('id', if classID is already known)\n * or full InternalItemReference ('generic').\n */\nexport interface Predicate {\n __isPredicate: true\n /**\n * Predicate expression to resolve.\n * Example: `data.identifier && parseInt(data.identifier, 10) === 123`.\n */\n predicate: string\n // TODO: Specify different subtypes for generic and ID?\n mode: 'generic' | 'id'\n}\n\ntype WithPredicatesResolved<T> = ReplaceType<T, Predicate, string | InternalItemReference>;\n\nfunction isPredicate(val: any): val is Predicate {\n return val && val.__isPredicate === true;\n}\n/**\n * Resolves any properties that should reference register item UUIDs,\n * but have predicates instead.\n */\nasync function resolvePredicates<T>(\n value: T,\n resolveRef: (predicate: string) => Promise<InternalItemReference>,\n): Promise<T extends Predicate ? string : WithPredicatesResolved<T>> {\n // NOTE: Return types are cast because https://github.com/microsoft/TypeScript/issues/33912.\n if (isPredicate(value)) {\n const ref = await resolveRef(value.predicate) as any;\n if (value.mode === 'generic') {\n return ref;\n } else {\n return ref.itemID;\n }\n } else if (value && typeof value === 'object') {\n if (Array.isArray(value)) {\n return await Promise.all(value.map((v: any) => resolvePredicates(v, resolveRef))) as any;\n } else {\n // Assume plain non-array object.\n for (const [key, v] of Object.entries(value)) {\n value[key as keyof typeof value] = await resolvePredicates(v, resolveRef);\n }\n return value as any;\n }\n } else {\n return value as any;\n }\n}\n\n\n/**\n * Returns an object changeset to update CR with new given proposal items.\n * Only applicable to CR at draft edit stage.\n */\nexport function updateCRObjectChangeset(\n /**\n * Change request data.\n */\n cr: Drafted | ReturnedForClarificationByManager | ReturnedForClarificationByControlBody,\n\n /**\n * Proposals by item path.\n * Will be merged with those already existing in `cr`.\n * If a proposal is undefined, it will be removed.\n */\n proposalItems: Record<string, ChangeProposal | null>,\n\n /**\n * New item data must be provided for additions and clarifications,\n * keyed by item path.\n */\n itemData: Record<string, RegisterItem<any>> = {},\n): ObjectChangeset {\n const changeset: ObjectChangeset = {};\n const newItems = { ...cr.items };\n for (const [itemPath, proposal] of Object.entries(proposalItems)) {\n // Update proposals on CR\n if (proposal !== null) {\n newItems[itemPath] = proposal;\n } else if (newItems[itemPath]) {\n delete newItems[itemPath];\n }\n // Add/remove item data\n if (proposal?.type === 'addition' || proposal?.type === 'clarification') {\n const proposedItemData = itemData[itemPath];\n if (proposedItemData === null || !isRegisterItem(proposedItemData)) {\n console.error(\"Unable to convert proposals to object changeset: original item data is missing\", itemPath);\n throw new Error(\"Unable to convert proposals to object changeset: original item data is missing\");\n }\n changeset[itemPathInCR(itemPath, cr.id)] = {\n // When editing a draft, we don’t care\n // about overwriting proposed item data so we omit oldValue.\n newValue: proposedItemData,\n };\n } else {\n changeset[itemPathInCR(itemPath, cr.id)] = {\n // When editing a draft, we don’t care\n // about overwriting proposed item data so we omit oldValue.\n newValue: null,\n };\n }\n }\n // Update main CR data\n const crPath = crIDToCRPath(cr.id);\n changeset[crPath] = {\n oldValue: cr,\n newValue: { ...cr, items: newItems, timeEdited: new Date() },\n };\n return changeset;\n}\n\n\n/**\n * Given change proposals, returns applicable changes\n * to objects in the dataset.\n */\nexport async function proposalsToObjectChangeset(\n crID: string,\n hasSubregisters: boolean,\n proposals: ProposalSet,\n itemData: Record<string, RegisterItem<any> | null>,\n newItemData: Record<string, RegisterItem<any> | null>,\n): Promise<ObjectChangeset> {\n const cs: ObjectChangeset = {};\n\n for (const [itemPath, proposal] of Object.entries(proposals)) {\n //const originalItem: RegisterItem<any> | undefined = (itemData[itemPath] ?? undefined);\n const itemRef = itemPathToItemRef(hasSubregisters, itemPath);\n\n if (proposal.type !== 'addition') {\n if (itemData[itemPath] === undefined) {\n console.error(\"Unable to convert proposals to object changeset: original item data is missing\", itemPath);\n throw new Error(\"Unable to convert proposals to object changeset: original item data is missing\");\n }\n if (proposal.type === 'amendment' && proposal.amendmentType === 'supersession') {\n Object.assign(cs, await proposalToObjectChangeset(crID, proposal, itemRef, itemPath, itemData, newItemData));\n } else {\n Object.assign(cs, await proposalToObjectChangeset(crID, proposal, itemRef, itemPath, itemData, newItemData));\n }\n } else {\n Object.assign(cs, await proposalToObjectChangeset(crID, proposal, itemRef, itemPath, itemData, newItemData));\n }\n }\n\n return cs;\n}\n\n// TODO: Refactor out the business logic of proposal approval.\n/**\n * Given a change proposal, returns applicable changes\n * to objects in the dataset.\n * Core logic of approving a proposal.\n * Takes a proposal and extra options (depending on proposal type).\n * Returns a Changeset containing register items at appropriate paths.\n */\nasync function proposalToObjectChangeset(\n crID: string,\n proposal: ChangeProposal,\n itemRef: InternalItemReference,\n itemPath: string,\n itemData: Record<string, RegisterItem<any> | null>,\n newItemData: Record<string, RegisterItem<any> | null>,\n): Promise<Changeset<Change<RegisterItem<any>>>> {\n let updatedItem: RegisterItem<any>;\n const changeset: Changeset<Change<RegisterItem<any>>> = {};\n\n const origItem = itemData[itemPath] ?? null;\n const newItem = newItemData[itemPathInCR(itemPath, crID)] ?? null;\n\n if (proposal.type !== 'addition') {\n if (origItem === null) {\n throw new Error(\"proposalToObjectChangeset() requires original item data for non-additions\");\n }\n\n updatedItem = { ...origItem };\n\n switch (proposal.type) {\n case 'clarification':\n if (newItem === null) {\n throw new Error(\"proposalToObjectChangeset() requires new item data for clarifications\");\n }\n //const clarification = proposal as Clarification;\n updatedItem.data = newItem.data //clarification.payload;\n break;\n case 'amendment':\n const amendment = proposal as Amendment;\n updatedItem.amendedInCR = crID;\n\n switch (amendment.amendmentType) {\n case 'retirement':\n updatedItem.status = 'retired';\n break;\n case 'invalidation':\n updatedItem.status = 'invalid';\n break;\n case 'supersession':\n const supersession = proposal as Supersession;\n updatedItem.status = 'superseded';\n updatedItem.supersededBy = supersession.supersedingItemIDs.map(itemID => ({\n itemID,\n classID: itemRef.classID,\n subregisterID: itemRef.subregisterID,\n }));\n for (const supersedingItemPath of updatedItem.supersededBy.map(ip => itemRefToItemPath(ip))) {\n const supersedingItemData = itemData[supersedingItemPath];\n if (supersedingItemData) {\n changeset[supersedingItemPath] = {\n oldValue: supersedingItemData,\n newValue: {\n ...supersedingItemData,\n supersedes: [ ...(supersedingItemData.supersedes ?? []), itemRef ],\n },\n };\n }\n }\n break;\n }\n break;\n }\n } else {\n if (newItem === null) {\n throw new Error(\"proposalToObjectChangeset() requires new item data for additions\");\n }\n updatedItem = {\n id: itemRef.itemID,\n data: newItem.data,\n status: 'valid',\n dateAccepted: new Date(),\n };\n }\n\n changeset[itemPath] = {\n oldValue: origItem,\n newValue: updatedItem,\n };\n\n return changeset;\n}\n\n\n// Helper\n\ntype ReplaceType<Type, FromType, ToType> = Type extends FromType\n ? ToType\n : Type extends object\n ? ReplaceTypes<Type, FromType, ToType>\n : Type;\n\ntype ReplaceTypes<ObjType extends object, FromType, ToType> = {\n [KeyType in keyof ObjType]:\n ReplaceType<ObjType[KeyType], FromType, ToType>;\n}\n"]}
@@ -23,8 +23,6 @@ var _objectChangeset = require("../../change-request/objectChangeset");
23
23
 
24
24
  var _cr = require("../../../types/cr");
25
25
 
26
- var _item = require("../../../types/item");
27
-
28
26
  var _protocolRegistry = require("../../protocolRegistry");
29
27
 
30
28
  var _itemPathUtils = require("../../itemPathUtils");
@@ -47,13 +45,16 @@ const RegisterHome = function () {
47
45
  customViews,
48
46
  registerMetadata,
49
47
  stakeholder,
50
- offline
48
+ offline,
49
+ itemClasses
51
50
  } = (0, _react.useContext)(_BrowserCtx.BrowserCtx);
52
51
  const {
53
52
  requestFileFromFilesystem,
54
53
  makeRandomID,
54
+ getObjectData,
55
55
  updateObjects,
56
- performOperation
56
+ performOperation,
57
+ getMapReducedData
57
58
  } = (0, _react.useContext)(_context.DatasetContext);
58
59
  const [newProposalIdea, setNewProposalIdea] = (0, _react.useState)('');
59
60
  const registerVersion = registerMetadata === null || registerMetadata === void 0 ? void 0 : registerMetadata.version;
@@ -81,8 +82,6 @@ const RegisterHome = function () {
81
82
  }
82
83
 
83
84
  async function getCRImportChangeset() {
84
- var _a, _b;
85
-
86
85
  if (!requestFileFromFilesystem) {
87
86
  throw new Error("Cannot request file from filesystem");
88
87
  }
@@ -100,36 +99,38 @@ const RegisterHome = function () {
100
99
  throw new Error("No file was selected");
101
100
  }
102
101
 
103
- const crID = (_a = fileData.proposalDraft) === null || _a === void 0 ? void 0 : _a.id;
104
-
105
- if (!crID) {
106
- throw new Error("Invalid file format");
107
- }
108
-
109
- if (fileData.proposalDraft.state !== _cr.State.DRAFT) {
110
- throw new Error(`Invalid proposal state (must be ${_cr.State.DRAFT})`);
111
- }
112
-
113
- const crPath = (0, _itemPathUtils.crIDToCRPath)(crID);
114
- const changeset = {
115
- [crPath]: {
116
- oldValue: null,
117
- newValue: fileData.proposalDraft
118
- }
119
- };
120
-
121
- for (const [itemPath, itemPayload] of Object.entries((_b = fileData.itemPayloads) !== null && _b !== void 0 ? _b : {})) {
122
- if (!(0, _item.isRegisterItem)(itemPayload)) {
123
- throw new Error("Invalid register item data found in proposal payloads");
102
+ if ((0, _cr.isImportableCR)(fileData)) {
103
+ const crID = fileData.proposalDraft.id;
104
+
105
+ try {
106
+ const changeset = await (0, _objectChangeset.importedProposalToCRObjectChangeset)(fileData, itemClasses, getObjectData, async function findObjects(predicate) {
107
+ const result = await getMapReducedData({
108
+ chains: {
109
+ _: {
110
+ mapFunc: `
111
+ const data = value.data;
112
+ if (data && (${predicate})) {
113
+ emit({ objectPath: key, objectData: value });
114
+ }
115
+ `
116
+ }
117
+ }
118
+ }); // NOTE: map returns an empty object if there’re no items,
119
+ // but we promise to return a list.
120
+
121
+ if (!Array.isArray(result._)) {
122
+ return [];
123
+ }
124
+
125
+ return result._;
126
+ });
127
+ return [changeset, crID];
128
+ } catch (e) {
129
+ throw new Error("Error reading proposal data");
124
130
  }
125
-
126
- changeset[(0, _itemPathUtils.itemPathInCR)(itemPath, crID)] = {
127
- oldValue: null,
128
- newValue: itemPayload
129
- };
131
+ } else {
132
+ throw new Error("Invalid proposal format");
130
133
  }
131
-
132
- return [changeset, crID];
133
134
  }
134
135
 
135
136
  async function handleImportProposal() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.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C,gBAAgB,KAAK,SAAS;YAC9B,CAAC,CAAC,IAAC,aAAa,IACZ,IAAI,EAAE,IAAC,OAAO,OAAG,EACjB,WAAW,EAAC,oCAA+B,GAC3C;YACJ,CAAC,CAAC,IAAC,aAAa,IACZ,IAAI,EAAC,cAAc,EACnB,KAAK,EAAC,0CAA0C,EAChD,WAAW,EAAE,0BACV,IAAI,CACJ,GACH,CAAC;IAET,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA;AAED,eAAe,YAAY,CAAC","sourcesContent":["/** @jsx jsx */\n/** @jsxFrag React.Fragment */\n\nimport React, { useContext, useState } from 'react';\n//import { Helmet } from 'react-helmet';\nimport { jsx, css } from '@emotion/react';\nimport { Menu, MenuDivider, MenuItem, InputGroup, Button, NonIdealState, Spinner, Callout } from '@blueprintjs/core';\nimport { DatasetContext } from '@riboseinc/paneron-extension-kit/context';\nimport { TabbedWorkspaceContext } from '@riboseinc/paneron-extension-kit/widgets/TabbedWorkspace/context';\nimport { BrowserCtx } from '../../BrowserCtx';\nimport { registerStakeholderPlain } from '../../RegisterStakeholder';\nimport { newCRObjectChangeset } from '../../change-request/objectChangeset';\nimport { State as ProposalState } from '../../../types/cr';\nimport { isRegisterItem } from '../../../types/item';\n\nimport { Protocols } from '../../protocolRegistry';\nimport { crIDToCRPath, itemPathInCR } from '../../itemPathUtils';\n\n\nconst RegisterHome: React.VoidFunctionComponent<Record<never, never>> =\nfunction () {\n const { spawnTab } = useContext(TabbedWorkspaceContext);\n const { customViews, registerMetadata, stakeholder, offline } = useContext(BrowserCtx);\n const { requestFileFromFilesystem, makeRandomID, updateObjects, performOperation } = useContext(DatasetContext);\n\n const [ newProposalIdea, setNewProposalIdea ] = useState<string>('');\n\n const registerVersion = registerMetadata?.version;\n const canCreateCR = (\n stakeholder &&\n stakeholder.role &&\n stakeholder.gitServerUsername?.trim() !== '' &&\n makeRandomID &&\n updateObjects &&\n (registerVersion?.id ?? '').trim() !== '');\n\n async function createCR(justification: string): Promise<string> {\n if (canCreateCR) {\n const id = await makeRandomID();\n await updateObjects({\n commitMessage: \"start new proposal\",\n objectChangeset: newCRObjectChangeset(\n id,\n justification,\n registerVersion!,\n stakeholder.gitServerUsername!,\n ),\n });\n return id;\n } else {\n throw new Error(\"Unable to create proposal: read-only dataset\");\n }\n }\n\n async function handleNewProposal() {\n if (newProposalIdea) {\n const crID = await performOperation(\"creating proposal\", createCR)(newProposalIdea);\n setNewProposalIdea('');\n spawnTab(`${Protocols.CHANGE_REQUEST}:${crIDToCRPath(crID)}`);\n }\n }\n\n async function getCRImportChangeset() {\n if (!requestFileFromFilesystem) {\n throw new Error(\"Cannot request file from filesystem\");\n }\n const data = await requestFileFromFilesystem({\n prompt: \"Select one register proposal JSON file\",\n filters: [\n { name: \"JSON files\", extensions: ['.json'] },\n ],\n });\n const fileData = Object.values(data)[0]!;\n if (!fileData) {\n throw new Error(\"No file was selected\");\n }\n const crID = fileData.proposalDraft?.id;\n if (!crID) {\n throw new Error(\"Invalid file format\");\n }\n if (fileData.proposalDraft.state !== ProposalState.DRAFT) {\n throw new Error(`Invalid proposal state (must be ${ProposalState.DRAFT})`);\n }\n const crPath = crIDToCRPath(crID);\n const changeset = {\n [crPath]: {\n oldValue: null,\n newValue: fileData.proposalDraft,\n },\n };\n for (const [itemPath, itemPayload] of Object.entries(fileData.itemPayloads ?? {})) {\n if (!isRegisterItem(itemPayload)) {\n throw new Error(\"Invalid register item data found in proposal payloads\");\n }\n changeset[itemPathInCR(itemPath, crID)] = {\n oldValue: null,\n newValue: itemPayload,\n };\n }\n return [changeset, crID];\n }\n\n async function handleImportProposal() {\n const [objectChangeset, crID] = await performOperation(\n 'reading proposal data',\n getCRImportChangeset,\n )();\n\n await performOperation(\n 'creating proposal',\n updateObjects ?? (async () => { throw new Error(\"Read-only dataset\"); }),\n )({\n commitMessage: \"import proposal\",\n objectChangeset,\n });\n\n setNewProposalIdea('');\n spawnTab(`${Protocols.CHANGE_REQUEST}:${crIDToCRPath(crID)}`);\n }\n\n const menu = (\n <Menu css={css`margin: 10px;`}>\n <MenuDivider title=\"Quick links\" />\n {customViews.map((cv, _) => \n <MenuItem\n key={cv.id}\n text={cv.label}\n title={cv.description}\n icon={cv.icon}\n onClick={() => spawnTab(`${Protocols.CUSTOM_VIEW}:${cv.id}/index`)}\n />\n )}\n {customViews.length > 0 ? <MenuDivider /> : null}\n\n <MenuItem\n text={`Propose a change to version ${registerMetadata?.version?.id ?? '(missing)'}`}\n disabled={!canCreateCR}\n icon=\"lightbulb\"\n title={canCreateCR\n ? \"A blank proposal will be created and opened in a new tab.\"\n : undefined}>\n <InputGroup\n value={newProposalIdea || undefined}\n placeholder=\"Your idea…\"\n title=\"Justification draft (you can change this later)\"\n onChange={evt => setNewProposalIdea(evt.currentTarget.value)}\n rightElement={\n <Button\n small\n intent={newProposalIdea ? 'primary': undefined}\n disabled={!newProposalIdea}\n onClick={handleNewProposal}\n icon=\"tick\"\n />\n }\n />\n </MenuItem>\n <MenuItem\n text=\"Import proposal\"\n icon=\"import\"\n onClick={handleImportProposal}\n />\n <MenuItem\n text=\"View register metadata\"\n icon=\"properties\"\n onClick={() => spawnTab(Protocols.REGISTER_META)}\n />\n </Menu>\n );\n\n const intro = <Callout intent=\"primary\" css={css`text-align: left;`}>\n {stakeholder\n ? <>You can create proposals as {registerStakeholderPlain(stakeholder)}.</>\n : offline\n ? <>\n Because this repository is offline (no remote configured),\n and remote username is currently required for proposal,\n you cannot create proposals.</>\n : <>\n Since your remote username is not in the list of stakeholders,\n you cannot create proposals currently.\n </>}\n </Callout>\n\n const greeting = registerMetadata\n ? <NonIdealState\n title={`Welcome to ${registerMetadata.name}`}\n description={<>\n {intro}\n {menu}\n </>}\n />\n : registerMetadata === undefined\n ? <NonIdealState\n icon={<Spinner />}\n description=\"Loading register information…\"\n />\n : <NonIdealState\n icon=\"heart-broken\"\n title=\"Register metadata is missing or invalid.\"\n description={<>\n {menu}\n </>}\n />;\n\n return greeting;\n}\n\nexport default RegisterHome;\n"]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C;YACJ,CAAC,CAAC,IAAC,aAAa,IACZ,IAAI,EAAC,cAAc,EACnB,KAAK,EAAC,0CAA0C,EAChD,WAAW,EAAE,0BACV,IAAI,CACJ,GACH,CAAC;IAET,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA;AAED,eAAe,YAAY,CAAC","sourcesContent":["/** @jsx jsx */\n/** @jsxFrag React.Fragment */\n\nimport React, { useContext, useState } from 'react';\n//import { Helmet } from 'react-helmet';\nimport { jsx, css } from '@emotion/react';\nimport type { ObjectChangeset } from '@riboseinc/paneron-extension-kit/types/objects';\nimport { Menu, MenuDivider, MenuItem, InputGroup, Button, NonIdealState, Spinner, Callout } from '@blueprintjs/core';\nimport { DatasetContext } from '@riboseinc/paneron-extension-kit/context';\nimport { TabbedWorkspaceContext } from '@riboseinc/paneron-extension-kit/widgets/TabbedWorkspace/context';\nimport { BrowserCtx } from '../../BrowserCtx';\nimport { registerStakeholderPlain } from '../../RegisterStakeholder';\nimport { newCRObjectChangeset, importedProposalToCRObjectChangeset } from '../../change-request/objectChangeset';\nimport { isImportableCR } from '../../../types/cr';\nimport { Protocols } from '../../protocolRegistry';\nimport { crIDToCRPath } from '../../itemPathUtils';\n\n\nconst RegisterHome: React.VoidFunctionComponent<Record<never, never>> =\nfunction () {\n const { spawnTab } = useContext(TabbedWorkspaceContext);\n const { customViews, registerMetadata, stakeholder, offline, itemClasses } = useContext(BrowserCtx);\n const {\n requestFileFromFilesystem,\n makeRandomID,\n getObjectData,\n updateObjects,\n performOperation,\n getMapReducedData,\n } = useContext(DatasetContext);\n\n const [ newProposalIdea, setNewProposalIdea ] = useState<string>('');\n\n const registerVersion = registerMetadata?.version;\n const canCreateCR = (\n stakeholder &&\n stakeholder.role &&\n stakeholder.gitServerUsername?.trim() !== '' &&\n makeRandomID &&\n updateObjects &&\n (registerVersion?.id ?? '').trim() !== '');\n\n async function createCR(justification: string): Promise<string> {\n if (canCreateCR) {\n const id = await makeRandomID();\n await updateObjects({\n commitMessage: \"start new proposal\",\n objectChangeset: newCRObjectChangeset(\n id,\n justification,\n registerVersion!,\n stakeholder.gitServerUsername!,\n ),\n });\n return id;\n } else {\n throw new Error(\"Unable to create proposal: read-only dataset\");\n }\n }\n\n async function handleNewProposal() {\n if (newProposalIdea) {\n const crID = await performOperation(\"creating proposal\", createCR)(newProposalIdea);\n setNewProposalIdea('');\n spawnTab(`${Protocols.CHANGE_REQUEST}:${crIDToCRPath(crID)}`);\n }\n }\n\n async function getCRImportChangeset(): Promise<[ObjectChangeset, string]> {\n if (!requestFileFromFilesystem) {\n throw new Error(\"Cannot request file from filesystem\");\n }\n const data = await requestFileFromFilesystem({\n prompt: \"Select one register proposal JSON file\",\n filters: [\n { name: \"JSON files\", extensions: ['.json'] },\n ],\n });\n const fileData = Object.values(data)[0]!;\n if (!fileData) {\n throw new Error(\"No file was selected\");\n }\n if (isImportableCR(fileData)) {\n const crID = fileData.proposalDraft.id;\n try {\n const changeset = await importedProposalToCRObjectChangeset(\n fileData,\n itemClasses,\n getObjectData,\n async function findObjects(predicate: string) {\n const result = (await getMapReducedData({\n chains: {\n _: {\n mapFunc: `\n const data = value.data;\n if (data && (${predicate})) {\n emit({ objectPath: key, objectData: value });\n }\n `,\n },\n },\n }));\n // NOTE: map returns an empty object if there’re no items,\n // but we promise to return a list.\n if (!Array.isArray(result._)) {\n return [];\n }\n return result._;\n },\n );\n return [changeset, crID];\n } catch (e) {\n throw new Error(\"Error reading proposal data\");\n }\n } else {\n throw new Error(\"Invalid proposal format\");\n }\n }\n\n async function handleImportProposal() {\n const [objectChangeset, crID] = await performOperation(\n 'reading proposal data',\n getCRImportChangeset,\n )();\n\n await performOperation(\n 'creating proposal',\n updateObjects ?? (async () => { throw new Error(\"Read-only dataset\"); }),\n )({\n commitMessage: \"import proposal\",\n objectChangeset,\n });\n\n setNewProposalIdea('');\n spawnTab(`${Protocols.CHANGE_REQUEST}:${crIDToCRPath(crID)}`);\n }\n\n const menu = (\n <Menu css={css`margin: 10px;`}>\n <MenuDivider title=\"Quick links\" />\n {customViews.map((cv, _) => \n <MenuItem\n key={cv.id}\n text={cv.label}\n title={cv.description}\n icon={cv.icon}\n onClick={() => spawnTab(`${Protocols.CUSTOM_VIEW}:${cv.id}/index`)}\n />\n )}\n {customViews.length > 0 ? <MenuDivider /> : null}\n\n <MenuItem\n text={`Propose a change to version ${registerMetadata?.version?.id ?? '(missing)'}`}\n disabled={!canCreateCR}\n icon=\"lightbulb\"\n title={canCreateCR\n ? \"A blank proposal will be created and opened in a new tab.\"\n : undefined}>\n <InputGroup\n value={newProposalIdea || undefined}\n placeholder=\"Your idea…\"\n title=\"Justification draft (you can change this later)\"\n onChange={evt => setNewProposalIdea(evt.currentTarget.value)}\n rightElement={\n <Button\n small\n intent={newProposalIdea ? 'primary': undefined}\n disabled={!newProposalIdea}\n onClick={handleNewProposal}\n icon=\"tick\"\n />\n }\n />\n </MenuItem>\n <MenuItem\n text=\"Import proposal\"\n icon=\"import\"\n onClick={handleImportProposal}\n />\n <MenuItem\n text=\"View register metadata\"\n icon=\"properties\"\n onClick={() => spawnTab(Protocols.REGISTER_META)}\n />\n </Menu>\n );\n\n const intro = <Callout intent=\"primary\" css={css`text-align: left;`}>\n {stakeholder\n ? <>You can create proposals as {registerStakeholderPlain(stakeholder)}.</>\n : offline\n ? <>\n Because this repository is offline (no remote configured),\n and remote username is currently required for proposal,\n you cannot create proposals.</>\n : <>\n Since your remote username is not in the list of stakeholders,\n you cannot create proposals currently.\n </>}\n </Callout>\n\n const greeting = registerMetadata\n ? <NonIdealState\n title={`Welcome to ${registerMetadata.name}`}\n description={<>\n {intro}\n {menu}\n </>}\n />\n : registerMetadata === undefined\n ? <NonIdealState\n icon={<Spinner />}\n description=\"Loading register information…\"\n />\n : <NonIdealState\n icon=\"heart-broken\"\n title=\"Register metadata is missing or invalid.\"\n description={<>\n {menu}\n </>}\n />;\n\n return greeting;\n}\n\nexport default RegisterHome;\n"]}