@owlmeans/planning 0.1.18-rc.2 → 0.1.18-rc.21
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 +69 -26
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/planning/SKILL.md +157 -45
- package/build/aliases/types.d.ts +49 -0
- package/build/aliases/types.d.ts.map +1 -0
- package/build/aliases/types.js +2 -0
- package/build/aliases/types.js.map +1 -0
- package/build/aliases.d.ts +4 -0
- package/build/aliases.d.ts.map +1 -0
- package/build/aliases.js +27 -0
- package/build/aliases.js.map +1 -0
- package/build/consts.d.ts +23 -34
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +26 -25
- package/build/consts.js.map +1 -1
- package/build/entrypoints/types.d.ts +96 -0
- package/build/entrypoints/types.d.ts.map +1 -0
- package/build/entrypoints/types.js +2 -0
- package/build/entrypoints/types.js.map +1 -0
- package/build/entrypoints.d.ts +5 -1
- package/build/entrypoints.d.ts.map +1 -1
- package/build/entrypoints.js +17 -6
- package/build/entrypoints.js.map +1 -1
- package/build/errors.d.ts +41 -0
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js +61 -0
- package/build/errors.js.map +1 -1
- package/build/helpers/apply/consts.local.d.ts +7 -0
- package/build/helpers/apply/consts.local.d.ts.map +1 -0
- package/build/helpers/apply/consts.local.js +9 -0
- package/build/helpers/apply/consts.local.js.map +1 -0
- package/build/helpers/apply/types.d.ts +32 -0
- package/build/helpers/apply/types.d.ts.map +1 -0
- package/build/helpers/apply/types.js +2 -0
- package/build/helpers/apply/types.js.map +1 -0
- package/build/helpers/apply.d.ts +5 -23
- package/build/helpers/apply.d.ts.map +1 -1
- package/build/helpers/apply.js +121 -143
- package/build/helpers/apply.js.map +1 -1
- package/build/helpers/card/types.d.ts +20 -0
- package/build/helpers/card/types.d.ts.map +1 -0
- package/build/helpers/card/types.js +2 -0
- package/build/helpers/card/types.js.map +1 -0
- package/build/helpers/card.d.ts +11 -7
- package/build/helpers/card.d.ts.map +1 -1
- package/build/helpers/card.js +41 -28
- package/build/helpers/card.js.map +1 -1
- package/build/helpers/changes/consts.local.d.ts +13 -0
- package/build/helpers/changes/consts.local.d.ts.map +1 -0
- package/build/helpers/changes/consts.local.js +13 -0
- package/build/helpers/changes/consts.local.js.map +1 -0
- package/build/helpers/changes/types.d.ts +58 -0
- package/build/helpers/changes/types.d.ts.map +1 -0
- package/build/helpers/changes/types.js +2 -0
- package/build/helpers/changes/types.js.map +1 -0
- package/build/helpers/changes.d.ts +11 -42
- package/build/helpers/changes.d.ts.map +1 -1
- package/build/helpers/changes.js +234 -251
- package/build/helpers/changes.js.map +1 -1
- package/build/helpers/code/types.d.ts +27 -0
- package/build/helpers/code/types.d.ts.map +1 -0
- package/build/helpers/code/types.js +2 -0
- package/build/helpers/code/types.js.map +1 -0
- package/build/helpers/code.d.ts +6 -17
- package/build/helpers/code.d.ts.map +1 -1
- package/build/helpers/code.js +39 -40
- package/build/helpers/code.js.map +1 -1
- package/build/helpers/index.d.ts +12 -0
- package/build/helpers/index.d.ts.map +1 -1
- package/build/helpers/index.js +2 -0
- package/build/helpers/index.js.map +1 -1
- package/build/helpers/query/types.d.ts +23 -0
- package/build/helpers/query/types.d.ts.map +1 -0
- package/build/helpers/query/types.js +2 -0
- package/build/helpers/query/types.js.map +1 -0
- package/build/helpers/query.d.ts +25 -17
- package/build/helpers/query.d.ts.map +1 -1
- package/build/helpers/query.js +108 -280
- package/build/helpers/query.js.map +1 -1
- package/build/helpers/scoped/types.d.ts +59 -0
- package/build/helpers/scoped/types.d.ts.map +1 -0
- package/build/helpers/scoped/types.js +2 -0
- package/build/helpers/scoped/types.js.map +1 -0
- package/build/helpers/scoped.d.ts +24 -0
- package/build/helpers/scoped.d.ts.map +1 -0
- package/build/helpers/scoped.js +197 -0
- package/build/helpers/scoped.js.map +1 -0
- package/build/helpers/specification/types.d.ts +24 -0
- package/build/helpers/specification/types.d.ts.map +1 -0
- package/build/helpers/specification/types.js +2 -0
- package/build/helpers/specification/types.js.map +1 -0
- package/build/helpers/specification.d.ts +9 -13
- package/build/helpers/specification.d.ts.map +1 -1
- package/build/helpers/specification.js +47 -44
- package/build/helpers/specification.js.map +1 -1
- package/build/helpers/status/types.d.ts +48 -0
- package/build/helpers/status/types.d.ts.map +1 -0
- package/build/helpers/status/types.js +2 -0
- package/build/helpers/status/types.js.map +1 -0
- package/build/helpers/status.d.ts +16 -29
- package/build/helpers/status.d.ts.map +1 -1
- package/build/helpers/status.js +77 -73
- package/build/helpers/status.js.map +1 -1
- package/build/helpers/types.local.d.ts +17 -0
- package/build/helpers/types.local.d.ts.map +1 -0
- package/build/helpers/types.local.js +2 -0
- package/build/helpers/types.local.js.map +1 -0
- package/build/helpers/validate/types.d.ts +30 -0
- package/build/helpers/validate/types.d.ts.map +1 -0
- package/build/helpers/validate/types.js +2 -0
- package/build/helpers/validate/types.js.map +1 -0
- package/build/helpers/validate.d.ts +8 -19
- package/build/helpers/validate.d.ts.map +1 -1
- package/build/helpers/validate.js +74 -79
- package/build/helpers/validate.js.map +1 -1
- package/build/helpers/wire/types.d.ts +28 -0
- package/build/helpers/wire/types.d.ts.map +1 -0
- package/build/helpers/wire/types.js +2 -0
- package/build/helpers/wire/types.js.map +1 -0
- package/build/helpers/wire.d.ts +4 -0
- package/build/helpers/wire.d.ts.map +1 -0
- package/build/helpers/wire.js +215 -0
- package/build/helpers/wire.js.map +1 -0
- package/build/i18n/be.json +5 -0
- package/build/i18n/de.json +5 -0
- package/build/i18n/en.json +5 -0
- package/build/i18n/es.json +5 -0
- package/build/i18n/fr.json +56 -0
- package/build/i18n/pl.json +5 -0
- package/build/i18n/ru.json +5 -0
- package/build/i18n/uk.json +5 -0
- package/build/i18n.js +5 -4
- package/build/i18n.js.map +1 -1
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/models/index.d.ts +2 -3
- package/build/models/index.d.ts.map +1 -1
- package/build/models/index.js +1 -15
- package/build/models/index.js.map +1 -1
- package/build/models/model.d.ts +5 -0
- package/build/models/model.d.ts.map +1 -0
- package/build/models/model.js +16 -0
- package/build/models/model.js.map +1 -0
- package/build/models/project.d.ts +2 -1
- package/build/models/project.d.ts.map +1 -1
- package/build/models/project.js.map +1 -1
- package/build/models/specification.d.ts +2 -1
- package/build/models/specification.d.ts.map +1 -1
- package/build/models/specification.js.map +1 -1
- package/build/models/types.d.ts +69 -0
- package/build/models/types.d.ts.map +1 -0
- package/build/models/types.js +2 -0
- package/build/models/types.js.map +1 -0
- package/build/models/workcard.d.ts +2 -1
- package/build/models/workcard.d.ts.map +1 -1
- package/build/models/workcard.js +12 -12
- package/build/models/workcard.js.map +1 -1
- package/build/schemas.d.ts +10 -2
- package/build/schemas.d.ts.map +1 -1
- package/build/schemas.js +87 -1
- package/build/schemas.js.map +1 -1
- package/build/types.d.ts +199 -148
- package/build/types.d.ts.map +1 -1
- package/build/utils.d.ts +6 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +6 -0
- package/build/utils.js.map +1 -0
- package/package.json +11 -11
- package/src/aliases/types.ts +38 -0
- package/src/aliases.ts +31 -0
- package/src/consts.ts +26 -25
- package/src/entrypoints/types.ts +68 -0
- package/src/entrypoints.ts +34 -14
- package/src/errors.ts +71 -0
- package/src/helpers/apply/consts.local.ts +10 -0
- package/src/helpers/apply/types.ts +32 -0
- package/src/helpers/apply.ts +135 -152
- package/src/helpers/card/types.ts +20 -0
- package/src/helpers/card.ts +59 -33
- package/src/helpers/changes/consts.local.ts +17 -0
- package/src/helpers/changes/types.ts +66 -0
- package/src/helpers/changes.ts +267 -280
- package/src/helpers/code/types.ts +31 -0
- package/src/helpers/code.ts +52 -48
- package/src/helpers/index.ts +13 -0
- package/src/helpers/query/types.ts +26 -0
- package/src/helpers/query.ts +144 -314
- package/src/helpers/scoped/types.ts +64 -0
- package/src/helpers/scoped.ts +257 -0
- package/src/helpers/specification/types.ts +26 -0
- package/src/helpers/specification.ts +69 -51
- package/src/helpers/status/types.ts +46 -0
- package/src/helpers/status.ts +117 -93
- package/src/helpers/types.local.ts +18 -0
- package/src/helpers/validate/types.ts +30 -0
- package/src/helpers/validate.ts +84 -77
- package/src/helpers/wire/types.ts +31 -0
- package/src/helpers/wire.ts +251 -0
- package/src/i18n/be.json +5 -0
- package/src/i18n/de.json +5 -0
- package/src/i18n/en.json +5 -0
- package/src/i18n/es.json +5 -0
- package/src/i18n/fr.json +56 -0
- package/src/i18n/pl.json +5 -0
- package/src/i18n/ru.json +5 -0
- package/src/i18n/uk.json +5 -0
- package/src/i18n.ts +6 -4
- package/src/index.ts +4 -0
- package/src/models/index.ts +2 -17
- package/src/models/model.ts +18 -0
- package/src/models/project.ts +2 -1
- package/src/models/specification.ts +2 -1
- package/src/models/types.ts +70 -0
- package/src/models/workcard.ts +14 -16
- package/src/schemas.ts +98 -2
- package/src/types.ts +207 -126
- package/src/utils.ts +9 -0
- package/tests/apply.spec.ts +95 -31
- package/tests/code.spec.ts +9 -9
- package/tests/entrypoints.spec.ts +18 -2
- package/tests/error-status.spec.ts +6 -1
- package/tests/models.spec.ts +16 -15
- package/tests/query.spec.ts +13 -15
- package/tests/schemas.spec.ts +8 -8
- package/tests/scoped.spec.ts +154 -0
- package/tests/status.spec.ts +31 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/helpers/apply/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAExE,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;;;OAiBG;IACH,eAAe,EAAE,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,UAAU,EAAE,UAAU,KAAK,CAAC,GAAG,IAAI,CAAA;IAChH;;;;;;OAMG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,UAAU,KAAK,YAAY,EAAE,CAAA;CACrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/helpers/apply/types.ts"],"names":[],"mappings":""}
|
package/build/helpers/apply.d.ts
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
import type { Relationship, Transition, Workcard } from '../types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* - An already-applied transition (`seq <= card.seq`) returns the card unchanged: re-folding is
|
|
7
|
-
* safe.
|
|
8
|
-
* - Anything but the next seq (`card.seq + 1`, or 1 for a create with no card) is refused with
|
|
9
|
-
* `PlanningError('fold:out-of-order')`.
|
|
10
|
-
* - `create` builds the whole record from `changes` plus the transition's identity; `delete`
|
|
11
|
-
* answers `null`; `link`/`unlink` only move `seq`/`head`/`updatedAt` (the edges are
|
|
12
|
-
* {@link applyRelationship}'s); `update`/`transit` write `changes` — `fields` and `flows` merge,
|
|
13
|
-
* everything else replaces — and clear `unset`.
|
|
14
|
-
* - Every result has `seq = transition.seq`, `head = max(head, seq)`, `updatedAt = transition.at`.
|
|
15
|
-
*
|
|
16
|
-
* @throws {PlanningError} `planning:fold:out-of-order:…`
|
|
17
|
-
*/
|
|
2
|
+
import type { ApplyHelper } from './apply/types.js';
|
|
3
|
+
export declare const createApplyHelper: () => ApplyHelper;
|
|
4
|
+
export declare const applyHelper: ApplyHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `applyHelper.applyTransition(…)` */
|
|
18
6
|
export declare const applyTransition: <T extends Workcard = Workcard>(card: T | null | undefined, transition: Transition) => T | null;
|
|
19
|
-
/**
|
|
20
|
-
* The relationships after one transition. Pure and total, like {@link applyTransition}.
|
|
21
|
-
*
|
|
22
|
-
* `create` adds its `links`, `link` adds its `link`, `unlink` removes the matching edge, and a
|
|
23
|
-
* `delete` removes every edge touching the card. An edge that already exists is kept as it is, so
|
|
24
|
-
* re-folding adds nothing. Every other action answers the list unchanged. Always a new array.
|
|
25
|
-
*/
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `applyHelper.applyRelationship(…)` */
|
|
26
8
|
export declare const applyRelationship: (links: Relationship[], transition: Transition) => Relationship[];
|
|
27
9
|
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/helpers/apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAqB,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/helpers/apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAqB,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACxF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAMnD,eAAO,MAAM,iBAAiB,QAAO,WAiJpC,CAAA;AAED,eAAO,MAAM,WAAW,aAAsB,CAAA;AAE9C,iFAAiF;AACjF,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,QAAQ,GAAG,QAAQ,QACrD,CAAC,GAAG,IAAI,GAAG,SAAS,cAAc,UAAU,KACjD,CAAC,GAAG,IAAwD,CAAA;AAE/D,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,UAAW,YAAY,EAAE,cAAc,UAAU,KAAG,YAAY,EAC5C,CAAA"}
|
package/build/helpers/apply.js
CHANGED
|
@@ -1,162 +1,140 @@
|
|
|
1
1
|
import { IntrinsicStatus, TransitionAction } from '../consts.js';
|
|
2
2
|
import { PlanningError } from '../errors.js';
|
|
3
|
-
|
|
4
|
-
const IDENTITY_KEYS = new Set(['id', 'kind', 'type', 'entityId', 'seq', 'head', 'createdAt']);
|
|
5
|
-
/** Cannot be cleared: a record without them is not a record. */
|
|
6
|
-
const REQUIRED_KEYS = new Set([
|
|
7
|
-
...IDENTITY_KEYS, 'title', 'parents', 'status', 'intrinsic', 'flows', 'labels', 'fields',
|
|
8
|
-
]);
|
|
9
|
-
/** Merged shallowly into the card's own map rather than replacing it. */
|
|
10
|
-
const MERGED_KEYS = new Set(['fields', 'flows']);
|
|
3
|
+
import { IDENTITY_KEYS, MERGED_KEYS, REQUIRED_KEYS } from './apply/consts.local.js';
|
|
11
4
|
const clean = (record) => Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
export const createApplyHelper = () => {
|
|
6
|
+
const outOfOrder = (card, transition) => new PlanningError(`fold:out-of-order:${transition.card}:${card?.seq ?? 0}:${transition.seq}`);
|
|
7
|
+
const unsetOn = (record, paths) => {
|
|
8
|
+
for (const path of paths ?? []) {
|
|
9
|
+
const dot = path.indexOf('.');
|
|
10
|
+
if (dot > 0) {
|
|
11
|
+
const head = path.slice(0, dot);
|
|
12
|
+
const map = record[head];
|
|
13
|
+
if (MERGED_KEYS.has(head) && map != null && typeof map === 'object') {
|
|
14
|
+
delete map[path.slice(dot + 1)];
|
|
15
|
+
}
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!REQUIRED_KEYS.has(path)) {
|
|
19
|
+
delete record[path];
|
|
21
20
|
}
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (!REQUIRED_KEYS.has(path)) {
|
|
25
|
-
delete record[path];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const writeChanges = (record, changes) => {
|
|
30
|
-
for (const [key, value] of Object.entries(changes)) {
|
|
31
|
-
if (value === undefined || IDENTITY_KEYS.has(key)) {
|
|
32
|
-
continue;
|
|
33
21
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
};
|
|
23
|
+
const writeChanges = (record, changes) => {
|
|
24
|
+
for (const [key, value] of Object.entries(changes)) {
|
|
25
|
+
if (value === undefined || IDENTITY_KEYS.has(key)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (MERGED_KEYS.has(key)) {
|
|
29
|
+
const merged = { ...(record[key] ?? {}) };
|
|
30
|
+
for (const [entry, entryValue] of Object.entries(value ?? {})) {
|
|
31
|
+
if (entryValue === null) {
|
|
32
|
+
delete merged[entry];
|
|
33
|
+
}
|
|
34
|
+
else if (entryValue !== undefined) {
|
|
35
|
+
merged[entry] = entryValue;
|
|
36
|
+
}
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
record[key] = merged;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (value === null) {
|
|
42
|
+
if (!REQUIRED_KEYS.has(key)) {
|
|
43
|
+
delete record[key];
|
|
42
44
|
}
|
|
45
|
+
continue;
|
|
43
46
|
}
|
|
44
|
-
record[key] =
|
|
45
|
-
continue;
|
|
47
|
+
record[key] = value;
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
};
|
|
50
|
+
const applyTransition = (card, transition) => {
|
|
51
|
+
if (card != null && transition.seq <= card.seq) {
|
|
52
|
+
return card;
|
|
53
|
+
}
|
|
54
|
+
if (card == null) {
|
|
55
|
+
if (transition.action === TransitionAction.Delete) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (transition.action !== TransitionAction.Create || transition.seq !== 1) {
|
|
59
|
+
throw outOfOrder(card, transition);
|
|
50
60
|
}
|
|
51
|
-
continue;
|
|
52
61
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* THE fold: the card after one transition. Pure, total, no I/O — every store (memory, Mongo, a
|
|
58
|
-
* client mirror) folds with this and nothing else, so one log always means one card.
|
|
59
|
-
*
|
|
60
|
-
* - An already-applied transition (`seq <= card.seq`) returns the card unchanged: re-folding is
|
|
61
|
-
* safe.
|
|
62
|
-
* - Anything but the next seq (`card.seq + 1`, or 1 for a create with no card) is refused with
|
|
63
|
-
* `PlanningError('fold:out-of-order')`.
|
|
64
|
-
* - `create` builds the whole record from `changes` plus the transition's identity; `delete`
|
|
65
|
-
* answers `null`; `link`/`unlink` only move `seq`/`head`/`updatedAt` (the edges are
|
|
66
|
-
* {@link applyRelationship}'s); `update`/`transit` write `changes` — `fields` and `flows` merge,
|
|
67
|
-
* everything else replaces — and clear `unset`.
|
|
68
|
-
* - Every result has `seq = transition.seq`, `head = max(head, seq)`, `updatedAt = transition.at`.
|
|
69
|
-
*
|
|
70
|
-
* @throws {PlanningError} `planning:fold:out-of-order:…`
|
|
71
|
-
*/
|
|
72
|
-
export const applyTransition = (card, transition) => {
|
|
73
|
-
if (card != null && transition.seq <= card.seq) {
|
|
74
|
-
return card;
|
|
75
|
-
}
|
|
76
|
-
if (card == null) {
|
|
62
|
+
else if (transition.seq !== card.seq + 1) {
|
|
63
|
+
throw outOfOrder(card, transition);
|
|
64
|
+
}
|
|
77
65
|
if (transition.action === TransitionAction.Delete) {
|
|
78
66
|
return null;
|
|
79
67
|
}
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
const head = Math.max(card?.head ?? card?.seq ?? 0, transition.seq);
|
|
69
|
+
const changes = structuredClone(transition.changes ?? {});
|
|
70
|
+
if (transition.action === TransitionAction.Create) {
|
|
71
|
+
const record = {
|
|
72
|
+
parents: [], labels: [], fields: {}, flows: {}, status: '', intrinsic: IntrinsicStatus.Planned,
|
|
73
|
+
};
|
|
74
|
+
writeChanges(record, changes);
|
|
75
|
+
unsetOn(record, transition.unset);
|
|
76
|
+
return clean({
|
|
77
|
+
...record,
|
|
78
|
+
id: transition.card,
|
|
79
|
+
kind: transition.kind,
|
|
80
|
+
type: transition.type,
|
|
81
|
+
entityId: transition.entityId,
|
|
82
|
+
seq: transition.seq,
|
|
83
|
+
head,
|
|
84
|
+
createdAt: transition.at,
|
|
85
|
+
updatedAt: transition.at,
|
|
86
|
+
});
|
|
82
87
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const edgeOf = (transition, draft) => clean({
|
|
121
|
-
entityId: transition.entityId,
|
|
122
|
-
type: draft.type,
|
|
123
|
-
from: draft.from ?? transition.card,
|
|
124
|
-
to: draft.to,
|
|
125
|
-
project: transition.project,
|
|
126
|
-
fields: draft.fields == null ? undefined : structuredClone(draft.fields),
|
|
127
|
-
createdAt: transition.at,
|
|
128
|
-
transition: transition.id,
|
|
129
|
-
});
|
|
130
|
-
const sameEdge = (left, right) => left.entityId === right.entityId && left.from === right.from && left.to === right.to && left.type === right.type;
|
|
131
|
-
/**
|
|
132
|
-
* The relationships after one transition. Pure and total, like {@link applyTransition}.
|
|
133
|
-
*
|
|
134
|
-
* `create` adds its `links`, `link` adds its `link`, `unlink` removes the matching edge, and a
|
|
135
|
-
* `delete` removes every edge touching the card. An edge that already exists is kept as it is, so
|
|
136
|
-
* re-folding adds nothing. Every other action answers the list unchanged. Always a new array.
|
|
137
|
-
*/
|
|
138
|
-
export const applyRelationship = (links, transition) => {
|
|
139
|
-
const add = (drafts) => drafts.reduce((result, draft) => {
|
|
140
|
-
const edge = edgeOf(transition, draft);
|
|
141
|
-
return result.some(existing => sameEdge(existing, edge)) ? result : [...result, edge];
|
|
142
|
-
}, [...links]);
|
|
143
|
-
switch (transition.action) {
|
|
144
|
-
case TransitionAction.Create:
|
|
145
|
-
return add(transition.links ?? []);
|
|
146
|
-
case TransitionAction.Link:
|
|
147
|
-
return add(transition.link == null ? [] : [transition.link]);
|
|
148
|
-
case TransitionAction.Unlink: {
|
|
149
|
-
if (transition.link == null) {
|
|
150
|
-
return [...links];
|
|
88
|
+
const record = structuredClone(card);
|
|
89
|
+
if (transition.action === TransitionAction.Update || transition.action === TransitionAction.Transit) {
|
|
90
|
+
writeChanges(record, changes);
|
|
91
|
+
unsetOn(record, transition.unset);
|
|
92
|
+
}
|
|
93
|
+
record.seq = transition.seq;
|
|
94
|
+
record.head = head;
|
|
95
|
+
record.updatedAt = transition.at;
|
|
96
|
+
return clean(record);
|
|
97
|
+
};
|
|
98
|
+
const edgeOf = (transition, draft) => clean({
|
|
99
|
+
entityId: transition.entityId,
|
|
100
|
+
type: draft.type,
|
|
101
|
+
from: draft.from ?? transition.card,
|
|
102
|
+
to: draft.to,
|
|
103
|
+
project: transition.project,
|
|
104
|
+
fields: draft.fields == null ? undefined : structuredClone(draft.fields),
|
|
105
|
+
createdAt: transition.at,
|
|
106
|
+
transition: transition.id,
|
|
107
|
+
});
|
|
108
|
+
const sameEdge = (left, right) => left.entityId === right.entityId && left.from === right.from && left.to === right.to && left.type === right.type;
|
|
109
|
+
const applyRelationship = (links, transition) => {
|
|
110
|
+
const add = (drafts) => drafts.reduce((result, draft) => {
|
|
111
|
+
const edge = edgeOf(transition, draft);
|
|
112
|
+
return result.some(existing => sameEdge(existing, edge)) ? result : [...result, edge];
|
|
113
|
+
}, [...links]);
|
|
114
|
+
switch (transition.action) {
|
|
115
|
+
case TransitionAction.Create:
|
|
116
|
+
return add(transition.links ?? []);
|
|
117
|
+
case TransitionAction.Link:
|
|
118
|
+
return add(transition.link == null ? [] : [transition.link]);
|
|
119
|
+
case TransitionAction.Unlink: {
|
|
120
|
+
if (transition.link == null) {
|
|
121
|
+
return [...links];
|
|
122
|
+
}
|
|
123
|
+
const edge = edgeOf(transition, transition.link);
|
|
124
|
+
return links.filter(existing => !sameEdge(existing, edge));
|
|
151
125
|
}
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
case TransitionAction.Delete:
|
|
127
|
+
return links.filter(existing => existing.entityId !== transition.entityId
|
|
128
|
+
|| (existing.from !== transition.card && existing.to !== transition.card));
|
|
129
|
+
default:
|
|
130
|
+
return [...links];
|
|
154
131
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|| (existing.from !== transition.card && existing.to !== transition.card));
|
|
158
|
-
default:
|
|
159
|
-
return [...links];
|
|
160
|
-
}
|
|
132
|
+
};
|
|
133
|
+
return { applyTransition, applyRelationship };
|
|
161
134
|
};
|
|
135
|
+
export const applyHelper = createApplyHelper();
|
|
136
|
+
/** @deprecated compat:factory-refactor — use `applyHelper.applyTransition(…)` */
|
|
137
|
+
export const applyTransition = (card, transition) => applyHelper.applyTransition(card, transition);
|
|
138
|
+
/** @deprecated compat:factory-refactor — use `applyHelper.applyRelationship(…)` */
|
|
139
|
+
export const applyRelationship = (links, transition) => applyHelper.applyRelationship(links, transition);
|
|
162
140
|
//# sourceMappingURL=apply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/helpers/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAG5C,
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/helpers/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE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,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Card, Project, Specification, Workcard, WorkcardDraft } from '../../types.js';
|
|
2
|
+
/** The kind guards and the parent rules every record keeps. */
|
|
3
|
+
export interface CardHelper {
|
|
4
|
+
isProject: (card?: Workcard | null) => card is Project;
|
|
5
|
+
isCard: (card?: Workcard | null) => card is Card;
|
|
6
|
+
isSpecification: (card?: Workcard | null) => card is Specification;
|
|
7
|
+
/** `parents` with `parent` first and no repeats — the invariant every record keeps. */
|
|
8
|
+
normalizeParents: (parent?: string | null, parents?: string[] | null) => string[];
|
|
9
|
+
/** A draft with the collections every record carries filled in. */
|
|
10
|
+
cardDefaults: (draft: WorkcardDraft) => WorkcardDraft & Required<Pick<WorkcardDraft, 'parents' | 'labels' | 'fields'>>;
|
|
11
|
+
/** A transition was allocated for the card and has not been folded yet. */
|
|
12
|
+
isPending: (card: Pick<Workcard, 'seq' | 'head'>) => boolean;
|
|
13
|
+
parentOf: (card: Workcard) => string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The project a card belongs to: a project is its own; a card under a project is that project's;
|
|
16
|
+
* anything deeper is its parent's project, which needs the parent to answer.
|
|
17
|
+
*/
|
|
18
|
+
projectOf: (card: Workcard, parent?: Workcard | null) => string | undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/helpers/card/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE3F,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,OAAO,CAAA;IACtD,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,IAAI,CAAA;IAChD,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,aAAa,CAAA;IAClE,uFAAuF;IACvF,gBAAgB,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,MAAM,EAAE,CAAA;IACjF,mEAAmE;IACnE,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAA;IACtH,2EAA2E;IAC3E,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,MAAM,CAAC,KAAK,OAAO,CAAA;IAC5D,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,GAAG,SAAS,CAAA;IAChD;;;OAGG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,KAAK,MAAM,GAAG,SAAS,CAAA;CAC5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/helpers/card/types.ts"],"names":[],"mappings":""}
|
package/build/helpers/card.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import type { Card, Project, Specification, Workcard, WorkcardDraft } from '../types.js';
|
|
2
|
+
import type { CardHelper } from './card/types.js';
|
|
3
|
+
export declare const createCardHelper: () => CardHelper;
|
|
4
|
+
export declare const cardHelper: CardHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isProject(…)` */
|
|
2
6
|
export declare const isProject: (card?: Workcard | null) => card is Project;
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isCard(…)` */
|
|
3
8
|
export declare const isCard: (card?: Workcard | null) => card is Card;
|
|
9
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isSpecification(…)` */
|
|
4
10
|
export declare const isSpecification: (card?: Workcard | null) => card is Specification;
|
|
5
|
-
/**
|
|
11
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.normalizeParents(…)` */
|
|
6
12
|
export declare const normalizeParents: (parent?: string | null, parents?: string[] | null) => string[];
|
|
7
|
-
/**
|
|
13
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.cardDefaults(…)` */
|
|
8
14
|
export declare const cardDefaults: (draft: WorkcardDraft) => WorkcardDraft & Required<Pick<WorkcardDraft, 'parents' | 'labels' | 'fields'>>;
|
|
9
|
-
/**
|
|
15
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isPending(…)` */
|
|
10
16
|
export declare const isPending: (card: Pick<Workcard, 'seq' | 'head'>) => boolean;
|
|
17
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.parentOf(…)` */
|
|
11
18
|
export declare const parentOf: (card: Workcard) => string | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* The project a card belongs to: a project is its own; a card under a project is that project's;
|
|
14
|
-
* anything deeper is its parent's project, which needs the parent to answer.
|
|
15
|
-
*/
|
|
19
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.projectOf(…)` */
|
|
16
20
|
export declare const projectOf: (card: Workcard, parent?: Workcard | null) => string | undefined;
|
|
17
21
|
//# sourceMappingURL=card.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/helpers/card.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"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ind } from '../consts.js';
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
if (parent != null) {
|
|
27
|
-
return isProject(parent) ? parent.id : parent.parent;
|
|
28
|
-
}
|
|
29
|
-
return card.parent;
|
|
2
|
+
export const createCardHelper = () => {
|
|
3
|
+
const isProject = (card) => card?.kind === WorkcardKind.Project;
|
|
4
|
+
const isCard = (card) => card?.kind === WorkcardKind.Card;
|
|
5
|
+
const isSpecification = (card) => card?.kind === WorkcardKind.Specification;
|
|
6
|
+
const normalizeParents = (parent, parents) => [...new Set([...(parent != null && parent !== '' ? [parent] : []), ...(parents ?? [])])]
|
|
7
|
+
.filter(id => id !== '');
|
|
8
|
+
const cardDefaults = (draft) => ({
|
|
9
|
+
...draft,
|
|
10
|
+
parents: normalizeParents(draft.parent, draft.parents),
|
|
11
|
+
labels: [...new Set(draft.labels ?? [])],
|
|
12
|
+
fields: draft.fields ?? {},
|
|
13
|
+
});
|
|
14
|
+
const isPending = (card) => (card.head ?? card.seq) > card.seq;
|
|
15
|
+
const parentOf = (card) => card.parent ?? card.parents[0];
|
|
16
|
+
const projectOf = (card, parent) => {
|
|
17
|
+
if (isProject(card)) {
|
|
18
|
+
return card.id;
|
|
19
|
+
}
|
|
20
|
+
if (parent != null) {
|
|
21
|
+
return isProject(parent) ? parent.id : parent.parent;
|
|
22
|
+
}
|
|
23
|
+
return card.parent;
|
|
24
|
+
};
|
|
25
|
+
return { isProject, isCard, isSpecification, normalizeParents, cardDefaults, isPending, parentOf, projectOf };
|
|
30
26
|
};
|
|
27
|
+
export const cardHelper = createCardHelper();
|
|
28
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isProject(…)` */
|
|
29
|
+
export const isProject = (card) => cardHelper.isProject(card);
|
|
30
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isCard(…)` */
|
|
31
|
+
export const isCard = (card) => cardHelper.isCard(card);
|
|
32
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isSpecification(…)` */
|
|
33
|
+
export const isSpecification = (card) => cardHelper.isSpecification(card);
|
|
34
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.normalizeParents(…)` */
|
|
35
|
+
export const normalizeParents = (parent, parents) => cardHelper.normalizeParents(parent, parents);
|
|
36
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.cardDefaults(…)` */
|
|
37
|
+
export const cardDefaults = (draft) => cardHelper.cardDefaults(draft);
|
|
38
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.isPending(…)` */
|
|
39
|
+
export const isPending = (card) => cardHelper.isPending(card);
|
|
40
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.parentOf(…)` */
|
|
41
|
+
export const parentOf = (card) => cardHelper.parentOf(card);
|
|
42
|
+
/** @deprecated compat:factory-refactor — use `cardHelper.projectOf(…)` */
|
|
43
|
+
export const projectOf = (card, parent) => cardHelper.projectOf(card, parent);
|
|
31
44
|
//# sourceMappingURL=card.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card.js","sourceRoot":"","sources":["../../src/helpers/card.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"card.js","sourceRoot":"","sources":["../../src/helpers/card.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAI3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAe,EAAE;IAC/C,MAAM,SAAS,GAAG,CAAC,IAAsB,EAAmB,EAAE,CAAC,IAAI,EAAE,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C,MAAM,SAAS,GAAG,CAAC,IAAoC,EAAW,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;AAEtG,yEAAyE;AACzE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAc,EAAsB,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAEzF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAc,EAAE,MAAwB,EAAsB,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Never in a caller's changes: the transition itself carries them. */
|
|
2
|
+
export declare const IDENTITY_KEYS: string[];
|
|
3
|
+
/** Written once, from a create's draft; never by `changes` or `unset`, whatever the action. */
|
|
4
|
+
export declare const PROVENANCE_KEYS: string[];
|
|
5
|
+
/** Move only through `transit` (or a create's draft). */
|
|
6
|
+
export declare const FLOW_KEYS: string[];
|
|
7
|
+
/** Computed by the executor, never supplied. */
|
|
8
|
+
export declare const DERIVED_KEYS: string[];
|
|
9
|
+
/** Cannot be cleared. */
|
|
10
|
+
export declare const REQUIRED_KEYS: string[];
|
|
11
|
+
/** Changing one of these produces a new revision of a revisioned document. */
|
|
12
|
+
export declare const CONTENT_KEYS: string[];
|
|
13
|
+
//# sourceMappingURL=consts.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.d.ts","sourceRoot":"","sources":["../../../src/helpers/changes/consts.local.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,aAAa,UAAiE,CAAA;AAE3F,+FAA+F;AAC/F,eAAO,MAAM,eAAe,UAAgB,CAAA;AAE5C,yDAAyD;AACzD,eAAO,MAAM,SAAS,UAA+C,CAAA;AAErE,gDAAgD;AAChD,eAAO,MAAM,YAAY,UAA4B,CAAA;AAErD,yBAAyB;AACzB,eAAO,MAAM,aAAa,UAAiE,CAAA;AAE3F,8EAA8E;AAC9E,eAAO,MAAM,YAAY,UAAuC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Never in a caller's changes: the transition itself carries them. */
|
|
2
|
+
export const IDENTITY_KEYS = ['id', 'kind', 'type', 'entityId', 'seq', 'head', 'createdAt'];
|
|
3
|
+
/** Written once, from a create's draft; never by `changes` or `unset`, whatever the action. */
|
|
4
|
+
export const PROVENANCE_KEYS = ['createdBy'];
|
|
5
|
+
/** Move only through `transit` (or a create's draft). */
|
|
6
|
+
export const FLOW_KEYS = ['status', 'intrinsic', 'flows', 'closedAt'];
|
|
7
|
+
/** Computed by the executor, never supplied. */
|
|
8
|
+
export const DERIVED_KEYS = ['revision', 'bodyChars'];
|
|
9
|
+
/** Cannot be cleared. */
|
|
10
|
+
export const REQUIRED_KEYS = ['title', 'parents', 'labels', 'fields', 'category', 'format'];
|
|
11
|
+
/** Changing one of these produces a new revision of a revisioned document. */
|
|
12
|
+
export const CONTENT_KEYS = ['body', 'ref', 'format', 'version'];
|
|
13
|
+
//# sourceMappingURL=consts.local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.js","sourceRoot":"","sources":["../../../src/helpers/changes/consts.local.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;AAE3F,+FAA+F;AAC/F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,WAAW,CAAC,CAAA;AAE5C,yDAAyD;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;AAErE,gDAAgD;AAChD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;AAErD,yBAAyB;AACzB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;AAE3F,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA"}
|