@blue-repository/types 0.9.0 → 0.10.0
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/README.md +1 -1
- package/dist/meta.d.ts +2 -2
- package/dist/meta.d.ts.map +1 -1
- package/dist/meta.js +1 -0
- package/dist/meta.js.map +1 -1
- package/dist/packages/conversation/blue-ids.d.ts +2 -2
- package/dist/packages/conversation/blue-ids.js +2 -2
- package/dist/packages/conversation/contents/ChangeWorkflow.d.ts +1 -1
- package/dist/packages/conversation/contents/ChangeWorkflow.js +1 -1
- package/dist/packages/conversation/contents/ChangeWorkflow.js.map +1 -1
- package/dist/packages/conversation/contents/ProposeChangeWorkflow.d.ts +1 -1
- package/dist/packages/conversation/contents/ProposeChangeWorkflow.js +1 -1
- package/dist/packages/conversation/contents/ProposeChangeWorkflow.js.map +1 -1
- package/dist/packages/conversation/contents/index.d.ts +68 -68
- package/dist/packages/conversation/contents/index.d.ts.map +1 -1
- package/dist/packages/conversation/contents/index.js +6 -6
- package/dist/packages/conversation/contents/index.js.map +1 -1
- package/dist/packages/conversation/index.d.ts +76 -76
- package/dist/packages/conversation/meta.d.ts +8 -8
- package/dist/packages/conversation/meta.js +6 -6
- package/dist/packages/conversation/schemas/index.d.ts +2 -2
- package/dist/packages/conversation/schemas/index.js +2 -2
- package/dist/repository.d.ts +77 -77
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/meta.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const name: "Blue Repository";
|
|
2
|
-
export declare const repositoryVersions: readonly ["5C7dGdtZGYPee4HtCXqFF4XpRuhhXeuaiWNDpdcG2iie", "2m6QjrS7SGeuhqufTcuunxLCpHmrqykEFXZcqSyU6wUc"];
|
|
2
|
+
export declare const repositoryVersions: readonly ["5C7dGdtZGYPee4HtCXqFF4XpRuhhXeuaiWNDpdcG2iie", "2m6QjrS7SGeuhqufTcuunxLCpHmrqykEFXZcqSyU6wUc", "fWQgpx2U9V1wz6MqurHqeYfAbWxHP6ym1hsJfSb6aqt"];
|
|
3
3
|
declare const _default: {
|
|
4
4
|
readonly name: "Blue Repository";
|
|
5
|
-
readonly repositoryVersions: readonly ["5C7dGdtZGYPee4HtCXqFF4XpRuhhXeuaiWNDpdcG2iie", "2m6QjrS7SGeuhqufTcuunxLCpHmrqykEFXZcqSyU6wUc"];
|
|
5
|
+
readonly repositoryVersions: readonly ["5C7dGdtZGYPee4HtCXqFF4XpRuhhXeuaiWNDpdcG2iie", "2m6QjrS7SGeuhqufTcuunxLCpHmrqykEFXZcqSyU6wUc", "fWQgpx2U9V1wz6MqurHqeYfAbWxHP6ym1hsJfSb6aqt"];
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
8
8
|
//# sourceMappingURL=meta.d.ts.map
|
package/dist/meta.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAG,iBAA0B,CAAC;AAC/C,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAG,iBAA0B,CAAC;AAC/C,eAAO,MAAM,kBAAkB,0JAIrB,CAAC;;;;;AACX,wBAAqD"}
|
package/dist/meta.js
CHANGED
|
@@ -2,6 +2,7 @@ export const name = 'Blue Repository';
|
|
|
2
2
|
export const repositoryVersions = [
|
|
3
3
|
'5C7dGdtZGYPee4HtCXqFF4XpRuhhXeuaiWNDpdcG2iie',
|
|
4
4
|
'2m6QjrS7SGeuhqufTcuunxLCpHmrqykEFXZcqSyU6wUc',
|
|
5
|
+
'fWQgpx2U9V1wz6MqurHqeYfAbWxHP6ym1hsJfSb6aqt',
|
|
5
6
|
];
|
|
6
7
|
export default { name, repositoryVersions };
|
|
7
8
|
//# sourceMappingURL=meta.js.map
|
package/dist/meta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,iBAA0B,CAAC;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,8CAA8C;IAC9C,8CAA8C;
|
|
1
|
+
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,iBAA0B,CAAC;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,8CAA8C;IAC9C,8CAA8C;IAC9C,6CAA6C;CACrC,CAAC;AACX,eAAe,EAAE,IAAI,EAAE,kBAAkB,EAAW,CAAC"}
|
|
@@ -4,7 +4,7 @@ export declare const blueIds: {
|
|
|
4
4
|
readonly 'Conversation/Actor': "CN5efWVizJbRsMCw8YWRfT2q9vM9XfeGDN9wFvYcvMnQ";
|
|
5
5
|
readonly 'Conversation/Change Operation': "BoyJNkH7CAzjuuzbZFpxB7HguZVtLCxpBLnuYY5k1eqB";
|
|
6
6
|
readonly 'Conversation/Change Request': "9KDfK6k1HBAyHckj5VuWXFMLkgY5cJBESKT4eoq1bnrw";
|
|
7
|
-
readonly 'Conversation/Change Workflow': "
|
|
7
|
+
readonly 'Conversation/Change Workflow': "AKNj5zwzgAkXZo3psikJfoVxUcNfMBVgDrf4HDGWL1gm";
|
|
8
8
|
readonly 'Conversation/Chat Message': "AkUKoKY1hHY1CytCrAXDPKCd4md1QGmn1WNcQtWBsyAD";
|
|
9
9
|
readonly 'Conversation/Composite Timeline Channel': "HsNatiPt2YvmkWQoqtfrFCbdp75ZUBLBUkWeq84WTfnr";
|
|
10
10
|
readonly 'Conversation/Contracts Change Policy': "6FDVZRQwuhXdXtnXq8kRg3f3DM8SUdbN3TT8rSGJcS2U";
|
|
@@ -23,7 +23,7 @@ export declare const blueIds: {
|
|
|
23
23
|
readonly 'Conversation/Operation': "BoAiqVUZv9Fum3wFqaX2JnQMBHJLxJSo2V9U2UBmCfsC";
|
|
24
24
|
readonly 'Conversation/Operation Request': "HM4Ku4LFcjC5MxnhPMRwQ8w3BbHmJKKZfHTTzsd4jbJq";
|
|
25
25
|
readonly 'Conversation/Propose Change Operation': "2mJhqggRy7YTHK5bSeAitqhhjynpe8mApvQXXpcwPCxx";
|
|
26
|
-
readonly 'Conversation/Propose Change Workflow': "
|
|
26
|
+
readonly 'Conversation/Propose Change Workflow': "Ecj8Y7rb7kMCkNFfvyZ36CNB2JjCWrqy7BiHcvcNELEL";
|
|
27
27
|
readonly 'Conversation/Proposed Change Invalid': "EbGQYtYR9UNAxcn7auCCujXmnz6DWxMpqVcgYSsKE85M";
|
|
28
28
|
readonly 'Conversation/Reject Change Operation': "4T5AmhKAXSJAAHDEjtVJ2FQgCyz2qyd9qG5uoh627Ux6";
|
|
29
29
|
readonly 'Conversation/Reject Change Workflow': "GfqZJJtSJfd69v3pJ67XURdzhC4byWJZAstCh6i4X6MZ";
|
|
@@ -4,7 +4,7 @@ export const blueIds = {
|
|
|
4
4
|
'Conversation/Actor': 'CN5efWVizJbRsMCw8YWRfT2q9vM9XfeGDN9wFvYcvMnQ',
|
|
5
5
|
'Conversation/Change Operation': 'BoyJNkH7CAzjuuzbZFpxB7HguZVtLCxpBLnuYY5k1eqB',
|
|
6
6
|
'Conversation/Change Request': '9KDfK6k1HBAyHckj5VuWXFMLkgY5cJBESKT4eoq1bnrw',
|
|
7
|
-
'Conversation/Change Workflow': '
|
|
7
|
+
'Conversation/Change Workflow': 'AKNj5zwzgAkXZo3psikJfoVxUcNfMBVgDrf4HDGWL1gm',
|
|
8
8
|
'Conversation/Chat Message': 'AkUKoKY1hHY1CytCrAXDPKCd4md1QGmn1WNcQtWBsyAD',
|
|
9
9
|
'Conversation/Composite Timeline Channel': 'HsNatiPt2YvmkWQoqtfrFCbdp75ZUBLBUkWeq84WTfnr',
|
|
10
10
|
'Conversation/Contracts Change Policy': '6FDVZRQwuhXdXtnXq8kRg3f3DM8SUdbN3TT8rSGJcS2U',
|
|
@@ -23,7 +23,7 @@ export const blueIds = {
|
|
|
23
23
|
'Conversation/Operation': 'BoAiqVUZv9Fum3wFqaX2JnQMBHJLxJSo2V9U2UBmCfsC',
|
|
24
24
|
'Conversation/Operation Request': 'HM4Ku4LFcjC5MxnhPMRwQ8w3BbHmJKKZfHTTzsd4jbJq',
|
|
25
25
|
'Conversation/Propose Change Operation': '2mJhqggRy7YTHK5bSeAitqhhjynpe8mApvQXXpcwPCxx',
|
|
26
|
-
'Conversation/Propose Change Workflow': '
|
|
26
|
+
'Conversation/Propose Change Workflow': 'Ecj8Y7rb7kMCkNFfvyZ36CNB2JjCWrqy7BiHcvcNELEL',
|
|
27
27
|
'Conversation/Proposed Change Invalid': 'EbGQYtYR9UNAxcn7auCCujXmnz6DWxMpqVcgYSsKE85M',
|
|
28
28
|
'Conversation/Reject Change Operation': '4T5AmhKAXSJAAHDEjtVJ2FQgCyz2qyd9qG5uoh627Ux6',
|
|
29
29
|
'Conversation/Reject Change Workflow': 'GfqZJJtSJfd69v3pJ67XURdzhC4byWJZAstCh6i4X6MZ',
|
|
@@ -13,7 +13,7 @@ export declare const ChangeWorkflow: {
|
|
|
13
13
|
readonly type: {
|
|
14
14
|
readonly blueId: "DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K";
|
|
15
15
|
};
|
|
16
|
-
readonly value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const contractsMap = sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(contractsMap)) {\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nreturn {\n changeset: combinedChangeset\n};\n";
|
|
16
|
+
readonly value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const rawContractsMap = sectionDef.contracts && sectionDef.contracts.value\n ? sectionDef.contracts.value\n : sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(rawContractsMap)) {\n if (\n rawKey === 'type' ||\n rawKey === 'keyType' ||\n rawKey === 'valueType' ||\n rawKey === 'description'\n ) {\n continue;\n }\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nreturn {\n changeset: combinedChangeset\n};\n";
|
|
17
17
|
};
|
|
18
18
|
readonly name: "Prepare";
|
|
19
19
|
readonly type: {
|
|
@@ -14,7 +14,7 @@ export const ChangeWorkflow = {
|
|
|
14
14
|
type: {
|
|
15
15
|
blueId: 'DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K',
|
|
16
16
|
},
|
|
17
|
-
value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const contractsMap = sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(contractsMap)) {\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nreturn {\n changeset: combinedChangeset\n};\n",
|
|
17
|
+
value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const rawContractsMap = sectionDef.contracts && sectionDef.contracts.value\n ? sectionDef.contracts.value\n : sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(rawContractsMap)) {\n if (\n rawKey === 'type' ||\n rawKey === 'keyType' ||\n rawKey === 'valueType' ||\n rawKey === 'description'\n ) {\n continue;\n }\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nreturn {\n changeset: combinedChangeset\n};\n",
|
|
18
18
|
},
|
|
19
19
|
name: 'Prepare',
|
|
20
20
|
type: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChangeWorkflow.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/ChangeWorkflow.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,WAAW,EAAE,4DAA4D;IACzE,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE;QACP,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EACH,
|
|
1
|
+
{"version":3,"file":"ChangeWorkflow.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/ChangeWorkflow.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,WAAW,EAAE,4DAA4D;IACzE,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE;QACP,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EACH,8rWAA8rW;iBACjsW;gBACD,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ,MAAM,EAAE,8CAA8C;iBACvD;aACF;YACD;gBACE,SAAS,EAAE;oBACT,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EAAE,4BAA4B;iBACpC;gBACD,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE;oBACJ,MAAM,EAAE,8CAA8C;iBACvD;aACF;SACF;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,8CAA8C;KACvD;CACO,CAAC"}
|
|
@@ -19,7 +19,7 @@ export declare const ProposeChangeWorkflow: {
|
|
|
19
19
|
readonly type: {
|
|
20
20
|
readonly blueId: "DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K";
|
|
21
21
|
};
|
|
22
|
-
readonly value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const contractsMap = sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(contractsMap)) {\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfixValue = currentContract.postfix || '';\nconst path = '/proposedChange' + postfixValue;\n\nif (document(path)) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nconst proposedPayload = {\n changeDescription\n};\n\nproposedPayload.preparedChangeset = combinedChangeset;\n\nif (hasChangeset) {\n proposedPayload.changeset = requestChangeset;\n}\n\nconst hasSectionChangesData = addList.length || modifyList.length || removeList.length;\nif (hasSectionChangesData) {\n proposedPayload.sectionChanges = rawSectionChanges;\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: proposedPayload\n }]\n};\n";
|
|
22
|
+
readonly value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const rawContractsMap = sectionDef.contracts && sectionDef.contracts.value\n ? sectionDef.contracts.value\n : sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(rawContractsMap)) {\n if (\n rawKey === 'type' ||\n rawKey === 'keyType' ||\n rawKey === 'valueType' ||\n rawKey === 'description'\n ) {\n continue;\n }\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfixValue = currentContract.postfix || '';\nconst path = '/proposedChange' + postfixValue;\n\nif (document(path)) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nconst proposedPayload = {\n changeDescription\n};\n\nproposedPayload.preparedChangeset = combinedChangeset;\n\nif (hasChangeset) {\n proposedPayload.changeset = requestChangeset;\n}\n\nconst hasSectionChangesData = addList.length || modifyList.length || removeList.length;\nif (hasSectionChangesData) {\n proposedPayload.sectionChanges = rawSectionChanges;\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: proposedPayload\n }]\n};\n";
|
|
23
23
|
};
|
|
24
24
|
readonly name: "Prepare";
|
|
25
25
|
readonly type: {
|
|
@@ -20,7 +20,7 @@ export const ProposeChangeWorkflow = {
|
|
|
20
20
|
type: {
|
|
21
21
|
blueId: 'DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K',
|
|
22
22
|
},
|
|
23
|
-
value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const contractsMap = sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(contractsMap)) {\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfixValue = currentContract.postfix || '';\nconst path = '/proposedChange' + postfixValue;\n\nif (document(path)) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nconst proposedPayload = {\n changeDescription\n};\n\nproposedPayload.preparedChangeset = combinedChangeset;\n\nif (hasChangeset) {\n proposedPayload.changeset = requestChangeset;\n}\n\nconst hasSectionChangesData = addList.length || modifyList.length || removeList.length;\nif (hasSectionChangesData) {\n proposedPayload.sectionChanges = rawSectionChanges;\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: proposedPayload\n }]\n};\n",
|
|
23
|
+
value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const rawContractsMap = sectionDef.contracts && sectionDef.contracts.value\n ? sectionDef.contracts.value\n : sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(rawContractsMap)) {\n if (\n rawKey === 'type' ||\n rawKey === 'keyType' ||\n rawKey === 'valueType' ||\n rawKey === 'description'\n ) {\n continue;\n }\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfixValue = currentContract.postfix || '';\nconst path = '/proposedChange' + postfixValue;\n\nif (document(path)) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nconst proposedPayload = {\n changeDescription\n};\n\nproposedPayload.preparedChangeset = combinedChangeset;\n\nif (hasChangeset) {\n proposedPayload.changeset = requestChangeset;\n}\n\nconst hasSectionChangesData = addList.length || modifyList.length || removeList.length;\nif (hasSectionChangesData) {\n proposedPayload.sectionChanges = rawSectionChanges;\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: proposedPayload\n }]\n};\n",
|
|
24
24
|
},
|
|
25
25
|
name: 'Prepare',
|
|
26
26
|
type: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProposeChangeWorkflow.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/ProposeChangeWorkflow.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE,0DAA0D;IACvE,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE;QACP,WAAW,EACT,iEAAiE;QACnE,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,OAAO,EAAE;QACP,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EACH
|
|
1
|
+
{"version":3,"file":"ProposeChangeWorkflow.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/ProposeChangeWorkflow.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE,0DAA0D;IACvE,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE;QACP,WAAW,EACT,iEAAiE;QACnE,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,OAAO,EAAE;QACP,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EACH,+6XAA+6X;iBACl7X;gBACD,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ,MAAM,EAAE,8CAA8C;iBACvD;aACF;YACD;gBACE,SAAS,EAAE;oBACT,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EAAE,4BAA4B;iBACpC;gBACD,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE;oBACJ,MAAM,EAAE,8CAA8C;iBACvD;aACF;SACF;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,8CAA8C;KACvD;CACO,CAAC"}
|