@open-rlb/nestjs-amqp 2.1.1 → 2.2.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/package.json +6 -5
- package/schematics/add-auth-provider/index.d.ts +3 -0
- package/schematics/add-auth-provider/index.js +60 -0
- package/schematics/add-auth-provider/index.js.map +1 -0
- package/schematics/add-auth-provider/index.spec.ts +83 -0
- package/schematics/add-auth-provider/index.ts +83 -0
- package/schematics/add-auth-provider/schema.d.ts +18 -0
- package/schematics/add-auth-provider/schema.js +3 -0
- package/schematics/add-auth-provider/schema.js.map +1 -0
- package/schematics/add-auth-provider/schema.json +59 -0
- package/schematics/add-auth-provider/schema.ts +35 -0
- package/schematics/add-exchange/index.d.ts +3 -0
- package/schematics/add-exchange/index.js +49 -0
- package/schematics/add-exchange/index.js.map +1 -0
- package/schematics/add-exchange/index.spec.ts +65 -0
- package/schematics/add-exchange/index.ts +65 -0
- package/schematics/add-exchange/schema.d.ts +14 -0
- package/schematics/add-exchange/schema.js +3 -0
- package/schematics/add-exchange/schema.js.map +1 -0
- package/schematics/add-exchange/schema.json +50 -0
- package/schematics/add-exchange/schema.ts +26 -0
- package/schematics/add-exchange-binding/index.d.ts +3 -0
- package/schematics/add-exchange-binding/index.js +53 -0
- package/schematics/add-exchange-binding/index.js.map +1 -0
- package/schematics/add-exchange-binding/index.spec.ts +73 -0
- package/schematics/add-exchange-binding/index.ts +64 -0
- package/schematics/add-exchange-binding/schema.d.ts +8 -0
- package/schematics/add-exchange-binding/schema.js +3 -0
- package/schematics/add-exchange-binding/schema.js.map +1 -0
- package/schematics/add-exchange-binding/schema.json +36 -0
- package/schematics/add-exchange-binding/schema.ts +14 -0
- package/schematics/add-gateway/index.d.ts +4 -0
- package/schematics/add-gateway/index.js +105 -0
- package/schematics/add-gateway/index.js.map +1 -0
- package/schematics/add-gateway/index.spec.ts +163 -0
- package/schematics/add-gateway/index.ts +141 -0
- package/schematics/add-gateway/paths.d.ts +12 -0
- package/schematics/add-gateway/paths.js +87 -0
- package/schematics/add-gateway/paths.js.map +1 -0
- package/schematics/add-gateway/paths.ts +103 -0
- package/schematics/add-gateway/schema.d.ts +13 -0
- package/schematics/add-gateway/schema.js +3 -0
- package/schematics/add-gateway/schema.js.map +1 -0
- package/schematics/add-gateway/schema.json +63 -0
- package/schematics/add-gateway/schema.ts +24 -0
- package/schematics/add-gateway/wiring.d.ts +14 -0
- package/schematics/add-gateway/wiring.js +102 -0
- package/schematics/add-gateway/wiring.js.map +1 -0
- package/schematics/add-gateway/wiring.ts +115 -0
- package/schematics/add-metrics-topic/index.d.ts +3 -0
- package/schematics/add-metrics-topic/index.js +31 -0
- package/schematics/add-metrics-topic/index.js.map +1 -0
- package/schematics/add-metrics-topic/index.spec.ts +79 -0
- package/schematics/add-metrics-topic/index.ts +49 -0
- package/schematics/add-metrics-topic/schema.d.ts +10 -0
- package/schematics/add-metrics-topic/schema.js +3 -0
- package/schematics/add-metrics-topic/schema.js.map +1 -0
- package/schematics/add-metrics-topic/schema.json +48 -0
- package/schematics/add-metrics-topic/schema.ts +18 -0
- package/schematics/add-queue/index.d.ts +3 -0
- package/schematics/add-queue/index.js +48 -0
- package/schematics/add-queue/index.js.map +1 -0
- package/schematics/add-queue/index.spec.ts +75 -0
- package/schematics/add-queue/index.ts +74 -0
- package/schematics/add-queue/schema.d.ts +17 -0
- package/schematics/add-queue/schema.js +3 -0
- package/schematics/add-queue/schema.js.map +1 -0
- package/schematics/add-queue/schema.json +54 -0
- package/schematics/add-queue/schema.ts +32 -0
- package/schematics/add-reply-queue/index.d.ts +3 -0
- package/schematics/add-reply-queue/index.js +26 -0
- package/schematics/add-reply-queue/index.js.map +1 -0
- package/schematics/add-reply-queue/index.spec.ts +69 -0
- package/schematics/add-reply-queue/index.ts +33 -0
- package/schematics/add-reply-queue/schema.d.ts +6 -0
- package/schematics/add-reply-queue/schema.js +3 -0
- package/schematics/add-reply-queue/schema.js.map +1 -0
- package/schematics/add-reply-queue/schema.json +28 -0
- package/schematics/add-reply-queue/schema.ts +10 -0
- package/schematics/add-route/index.d.ts +3 -0
- package/schematics/add-route/index.js +57 -0
- package/schematics/add-route/index.js.map +1 -0
- package/schematics/add-route/index.spec.ts +75 -0
- package/schematics/add-route/index.ts +74 -0
- package/schematics/add-route/schema.d.ts +22 -0
- package/schematics/add-route/schema.js +3 -0
- package/schematics/add-route/schema.js.map +1 -0
- package/schematics/add-route/schema.json +74 -0
- package/schematics/add-route/schema.ts +43 -0
- package/schematics/add-topic/index.d.ts +3 -0
- package/schematics/add-topic/index.js +69 -0
- package/schematics/add-topic/index.js.map +1 -0
- package/schematics/add-topic/index.spec.ts +100 -0
- package/schematics/add-topic/index.ts +104 -0
- package/schematics/add-topic/schema.d.ts +18 -0
- package/schematics/add-topic/schema.js +3 -0
- package/schematics/add-topic/schema.js.map +1 -0
- package/schematics/add-topic/schema.json +63 -0
- package/schematics/add-topic/schema.ts +34 -0
- package/schematics/add-ws-event/index.d.ts +3 -0
- package/schematics/add-ws-event/index.js +53 -0
- package/schematics/add-ws-event/index.js.map +1 -0
- package/schematics/add-ws-event/index.spec.ts +85 -0
- package/schematics/add-ws-event/index.ts +72 -0
- package/schematics/add-ws-event/schema.d.ts +17 -0
- package/schematics/add-ws-event/schema.js +3 -0
- package/schematics/add-ws-event/schema.js.map +1 -0
- package/schematics/add-ws-event/schema.json +53 -0
- package/schematics/add-ws-event/schema.ts +33 -0
- package/schematics/collection.json +81 -1
- package/schematics/configure-broker/index.d.ts +3 -0
- package/schematics/configure-broker/index.js +41 -0
- package/schematics/configure-broker/index.js.map +1 -0
- package/schematics/configure-broker/index.spec.ts +62 -0
- package/schematics/configure-broker/index.ts +51 -0
- package/schematics/configure-broker/schema.d.ts +11 -0
- package/schematics/configure-broker/schema.js +3 -0
- package/schematics/configure-broker/schema.js.map +1 -0
- package/schematics/configure-broker/schema.json +47 -0
- package/schematics/configure-broker/schema.ts +20 -0
- package/schematics/enable-load-config/index.d.ts +3 -0
- package/schematics/enable-load-config/index.js +32 -0
- package/schematics/enable-load-config/index.js.map +1 -0
- package/schematics/enable-load-config/index.spec.ts +61 -0
- package/schematics/enable-load-config/index.ts +39 -0
- package/schematics/enable-load-config/schema.d.ts +8 -0
- package/schematics/enable-load-config/schema.js +3 -0
- package/schematics/enable-load-config/schema.js.map +1 -0
- package/schematics/enable-load-config/schema.json +36 -0
- package/schematics/enable-load-config/schema.ts +14 -0
- package/schematics/enable-retry/index.d.ts +3 -0
- package/schematics/enable-retry/index.js +51 -0
- package/schematics/enable-retry/index.js.map +1 -0
- package/schematics/enable-retry/index.spec.ts +73 -0
- package/schematics/enable-retry/index.ts +62 -0
- package/schematics/enable-retry/schema.d.ts +13 -0
- package/schematics/enable-retry/schema.js +3 -0
- package/schematics/enable-retry/schema.js.map +1 -0
- package/schematics/enable-retry/schema.json +64 -0
- package/schematics/enable-retry/schema.ts +24 -0
- package/schematics/enable-route-discovery/index.d.ts +3 -0
- package/schematics/enable-route-discovery/index.js +36 -0
- package/schematics/enable-route-discovery/index.js.map +1 -0
- package/schematics/enable-route-discovery/index.spec.ts +55 -0
- package/schematics/enable-route-discovery/index.ts +48 -0
- package/schematics/enable-route-discovery/schema.d.ts +9 -0
- package/schematics/enable-route-discovery/schema.js +3 -0
- package/schematics/enable-route-discovery/schema.js.map +1 -0
- package/schematics/enable-route-discovery/schema.json +44 -0
- package/schematics/enable-route-discovery/schema.ts +16 -0
- package/schematics/harden-gateway/index.d.ts +3 -0
- package/schematics/harden-gateway/index.js +93 -0
- package/schematics/harden-gateway/index.js.map +1 -0
- package/schematics/harden-gateway/index.spec.ts +105 -0
- package/schematics/harden-gateway/index.ts +108 -0
- package/schematics/harden-gateway/schema.d.ts +11 -0
- package/schematics/harden-gateway/schema.js +3 -0
- package/schematics/harden-gateway/schema.js.map +1 -0
- package/schematics/harden-gateway/schema.json +47 -0
- package/schematics/harden-gateway/schema.ts +20 -0
- package/schematics/nest-add/index.js +55 -832
- package/schematics/nest-add/index.js.map +1 -1
- package/schematics/nest-add/index.spec.ts +73 -0
- package/schematics/nest-add/index.ts +76 -917
- package/schematics/nest-add/init.schema.d.ts +1 -0
- package/schematics/nest-add/init.schema.ts +3 -0
- package/schematics/nest-add/schema.json +4 -43
- package/schematics/set-connection-name/index.d.ts +3 -0
- package/schematics/set-connection-name/index.js +34 -0
- package/schematics/set-connection-name/index.js.map +1 -0
- package/schematics/set-connection-name/index.spec.ts +48 -0
- package/schematics/set-connection-name/index.ts +42 -0
- package/schematics/set-connection-name/schema.d.ts +5 -0
- package/schematics/set-connection-name/schema.js +3 -0
- package/schematics/set-connection-name/schema.js.map +1 -0
- package/schematics/set-connection-name/schema.json +24 -0
- package/schematics/set-connection-name/schema.ts +8 -0
- package/schematics/utils/broker-yaml.util.d.ts +53 -0
- package/schematics/utils/broker-yaml.util.js +91 -0
- package/schematics/utils/broker-yaml.util.js.map +1 -0
- package/schematics/utils/broker-yaml.util.ts +172 -0
- package/schematics/utils/nest-wiring.util.d.ts +30 -0
- package/schematics/utils/nest-wiring.util.js +170 -0
- package/schematics/utils/nest-wiring.util.js.map +1 -0
- package/schematics/utils/nest-wiring.util.ts +211 -0
- package/schematics/utils/schematic-prompt.util.d.ts +7 -0
- package/schematics/utils/schematic-prompt.util.js +57 -0
- package/schematics/utils/schematic-prompt.util.js.map +1 -0
- package/schematics/utils/schematic-prompt.util.ts +82 -0
- package/schematics/utils/yaml-config.util.d.ts +22 -0
- package/schematics/utils/yaml-config.util.js +119 -0
- package/schematics/utils/yaml-config.util.js.map +1 -0
- package/schematics/utils/yaml-config.util.ts +167 -0
- /package/schematics/{nest-add → add-gateway}/files/acl/src/cache/in-memory-acl-store.ts +0 -0
- /package/schematics/{nest-add → add-gateway}/files/acl/src/modules/database/repository/acl.repository.ts +0 -0
- /package/schematics/{nest-add → add-gateway}/files/db-core/src/modules/database/repository/in-memory-collection.ts +0 -0
- /package/schematics/{nest-add → add-gateway}/files/gateway-admin/src/modules/database/repository/gateway.repository.ts +0 -0
- /package/schematics/{nest-add → add-gateway}/files/gateway-admin/src/modules/database/repository/route-sync.repository.ts +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONFIG_PATH = void 0;
|
|
4
|
+
exports.findConfigYaml = findConfigYaml;
|
|
5
|
+
exports.readConfigDoc = readConfigDoc;
|
|
6
|
+
exports.writeConfigDoc = writeConfigDoc;
|
|
7
|
+
exports.ensureSeqAt = ensureSeqAt;
|
|
8
|
+
exports.ensureMapAt = ensureMapAt;
|
|
9
|
+
exports.findSeqItemByKey = findSeqItemByKey;
|
|
10
|
+
exports.seqItemExists = seqItemExists;
|
|
11
|
+
exports.upsertSeqItemByKey = upsertSeqItemByKey;
|
|
12
|
+
exports.setIn = setIn;
|
|
13
|
+
exports.deleteSeqItemByKey = deleteSeqItemByKey;
|
|
14
|
+
exports.getScalar = getScalar;
|
|
15
|
+
const yaml_1 = require("yaml");
|
|
16
|
+
exports.DEFAULT_CONFIG_PATH = 'config/config.yaml';
|
|
17
|
+
function findConfigYaml(tree, preferred) {
|
|
18
|
+
const candidates = [preferred, exports.DEFAULT_CONFIG_PATH, 'src/config/config.yaml', 'config.yaml'].filter((c) => !!c);
|
|
19
|
+
for (const c of candidates) {
|
|
20
|
+
if (tree.exists(c))
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
let found;
|
|
24
|
+
tree.visit((p) => {
|
|
25
|
+
if (!found && p.endsWith('/config.yaml'))
|
|
26
|
+
found = p.replace(/^\//, '');
|
|
27
|
+
});
|
|
28
|
+
return found || preferred || exports.DEFAULT_CONFIG_PATH;
|
|
29
|
+
}
|
|
30
|
+
function readConfigDoc(tree, path) {
|
|
31
|
+
if (tree.exists(path)) {
|
|
32
|
+
const raw = tree.read(path).toString('utf-8');
|
|
33
|
+
return { doc: (0, yaml_1.parseDocument)(raw), existed: true };
|
|
34
|
+
}
|
|
35
|
+
return { doc: new yaml_1.Document({}), existed: false };
|
|
36
|
+
}
|
|
37
|
+
function writeConfigDoc(tree, path, doc) {
|
|
38
|
+
const out = doc.toString({ lineWidth: 0 });
|
|
39
|
+
if (tree.exists(path))
|
|
40
|
+
tree.overwrite(path, out);
|
|
41
|
+
else
|
|
42
|
+
tree.create(path, out);
|
|
43
|
+
}
|
|
44
|
+
function ensureSeqAt(doc, path) {
|
|
45
|
+
const node = doc.getIn(path, true);
|
|
46
|
+
if ((0, yaml_1.isSeq)(node))
|
|
47
|
+
return node;
|
|
48
|
+
const seq = new yaml_1.YAMLSeq();
|
|
49
|
+
doc.setIn(path, seq);
|
|
50
|
+
return seq;
|
|
51
|
+
}
|
|
52
|
+
function ensureMapAt(doc, path) {
|
|
53
|
+
const node = doc.getIn(path, true);
|
|
54
|
+
if ((0, yaml_1.isMap)(node))
|
|
55
|
+
return node;
|
|
56
|
+
const map = new yaml_1.YAMLMap();
|
|
57
|
+
doc.setIn(path, map);
|
|
58
|
+
return map;
|
|
59
|
+
}
|
|
60
|
+
function findSeqItemByKey(doc, path, keyField, key) {
|
|
61
|
+
const node = doc.getIn(path, true);
|
|
62
|
+
if (!(0, yaml_1.isSeq)(node))
|
|
63
|
+
return undefined;
|
|
64
|
+
return node.items.find((it) => (0, yaml_1.isMap)(it) && String(it.get(keyField)) === String(key));
|
|
65
|
+
}
|
|
66
|
+
function seqItemExists(doc, path, keyField, key) {
|
|
67
|
+
return !!findSeqItemByKey(doc, path, keyField, key);
|
|
68
|
+
}
|
|
69
|
+
function upsertSeqItemByKey(doc, path, keyField, item, opts = {}) {
|
|
70
|
+
const seq = ensureSeqAt(doc, path);
|
|
71
|
+
const clean = stripUndefined(item);
|
|
72
|
+
const existing = seq.items.find((it) => (0, yaml_1.isMap)(it) && String(it.get(keyField)) === String(clean[keyField]));
|
|
73
|
+
if (!existing) {
|
|
74
|
+
const node = doc.createNode(clean);
|
|
75
|
+
if (opts.commentBefore)
|
|
76
|
+
node.commentBefore = ` ${opts.commentBefore}`;
|
|
77
|
+
seq.flow = false;
|
|
78
|
+
node.flow = false;
|
|
79
|
+
seq.add(node);
|
|
80
|
+
return 'created';
|
|
81
|
+
}
|
|
82
|
+
if (!opts.overwrite)
|
|
83
|
+
return 'unchanged';
|
|
84
|
+
const before = existing.toString();
|
|
85
|
+
for (const [k, v] of Object.entries(clean)) {
|
|
86
|
+
existing.set(k, doc.createNode(v));
|
|
87
|
+
}
|
|
88
|
+
return existing.toString() === before ? 'unchanged' : 'updated';
|
|
89
|
+
}
|
|
90
|
+
function setIn(doc, path, value) {
|
|
91
|
+
const prev = doc.getIn(path, false);
|
|
92
|
+
const existed = prev !== undefined;
|
|
93
|
+
if (existed && JSON.stringify(prev) === JSON.stringify(value))
|
|
94
|
+
return 'unchanged';
|
|
95
|
+
doc.setIn(path, doc.createNode(value));
|
|
96
|
+
return existed ? 'updated' : 'created';
|
|
97
|
+
}
|
|
98
|
+
function deleteSeqItemByKey(doc, path, keyField, key) {
|
|
99
|
+
const node = doc.getIn(path, true);
|
|
100
|
+
if (!(0, yaml_1.isSeq)(node))
|
|
101
|
+
return false;
|
|
102
|
+
const idx = node.items.findIndex((it) => (0, yaml_1.isMap)(it) && String(it.get(keyField)) === String(key));
|
|
103
|
+
if (idx === -1)
|
|
104
|
+
return false;
|
|
105
|
+
node.items.splice(idx, 1);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
function getScalar(doc, path) {
|
|
109
|
+
return doc.getIn(path, false);
|
|
110
|
+
}
|
|
111
|
+
function stripUndefined(obj) {
|
|
112
|
+
const out = {};
|
|
113
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
114
|
+
if (v !== undefined)
|
|
115
|
+
out[k] = v;
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=yaml-config.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-config.util.js","sourceRoot":"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K,CAAC;IAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAA,YAAK,EAAC,EAAE,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAChG,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC1B,OAAO,IAAI,CAAC;AACd,CAAC;AAGD,SAAgB,SAAS,CAAC,GAAa,EAAE,IAAyB;IAChE,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,cAAc,CAAC,GAA4B;IAClD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Tree } from '@angular-devkit/schematics';
|
|
2
|
+
import { Document, isMap, isSeq, parseDocument, YAMLMap, YAMLSeq } from 'yaml';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Comment-preserving `config.yaml` editing shared by every YAML schematic.
|
|
6
|
+
*
|
|
7
|
+
* All edits go through the `yaml` (eemeli) CST/Document API so existing comments, key order and
|
|
8
|
+
* formatting survive a round-trip — a plain `js-yaml` load/dump would strip them. The helpers are
|
|
9
|
+
* deliberately data-only: prompting and the "create the missing dependency?" flow live in each
|
|
10
|
+
* schematic's index.ts, so this module never triggers interactive I/O and stays easy to unit-test.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_CONFIG_PATH = 'config/config.yaml';
|
|
14
|
+
|
|
15
|
+
/** Outcome of an idempotent upsert, surfaced to the user as a log line. */
|
|
16
|
+
export type UpsertOutcome = 'created' | 'updated' | 'unchanged';
|
|
17
|
+
|
|
18
|
+
/** Locate the project's config.yaml, preferring an explicit path, then the usual locations, then a scan. */
|
|
19
|
+
export function findConfigYaml(tree: Tree, preferred?: string): string {
|
|
20
|
+
const candidates = [preferred, DEFAULT_CONFIG_PATH, 'src/config/config.yaml', 'config.yaml'].filter(
|
|
21
|
+
(c): c is string => !!c,
|
|
22
|
+
);
|
|
23
|
+
for (const c of candidates) {
|
|
24
|
+
if (tree.exists(c)) return c;
|
|
25
|
+
}
|
|
26
|
+
let found: string | undefined;
|
|
27
|
+
tree.visit((p) => {
|
|
28
|
+
if (!found && p.endsWith('/config.yaml')) found = p.replace(/^\//, '');
|
|
29
|
+
});
|
|
30
|
+
return found || preferred || DEFAULT_CONFIG_PATH;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Parse the config into a mutable Document (or a fresh empty one when the file does not exist yet). */
|
|
34
|
+
export function readConfigDoc(tree: Tree, path: string): { doc: Document; existed: boolean } {
|
|
35
|
+
if (tree.exists(path)) {
|
|
36
|
+
const raw = tree.read(path)!.toString('utf-8');
|
|
37
|
+
return { doc: parseDocument(raw), existed: true };
|
|
38
|
+
}
|
|
39
|
+
return { doc: new Document({}), existed: false };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Serialize the Document back to the tree (create or overwrite). `lineWidth: 0` disables line wrapping. */
|
|
43
|
+
export function writeConfigDoc(tree: Tree, path: string, doc: Document): void {
|
|
44
|
+
const out = doc.toString({ lineWidth: 0 });
|
|
45
|
+
if (tree.exists(path)) tree.overwrite(path, out);
|
|
46
|
+
else tree.create(path, out);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Ensure `path` resolves to a YAMLSeq, creating (and any missing parent maps) if needed. */
|
|
50
|
+
export function ensureSeqAt(doc: Document, path: (string | number)[]): YAMLSeq {
|
|
51
|
+
const node = doc.getIn(path, true);
|
|
52
|
+
if (isSeq(node)) return node;
|
|
53
|
+
const seq = new YAMLSeq();
|
|
54
|
+
doc.setIn(path, seq);
|
|
55
|
+
return seq;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Ensure `path` resolves to a YAMLMap, creating (and any missing parent maps) if needed. */
|
|
59
|
+
export function ensureMapAt(doc: Document, path: (string | number)[]): YAMLMap {
|
|
60
|
+
const node = doc.getIn(path, true);
|
|
61
|
+
if (isMap(node)) return node;
|
|
62
|
+
const map = new YAMLMap();
|
|
63
|
+
doc.setIn(path, map);
|
|
64
|
+
return map;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Find a map item in the seq at `path` whose `keyField` equals `key` (string-compared). */
|
|
68
|
+
export function findSeqItemByKey(
|
|
69
|
+
doc: Document,
|
|
70
|
+
path: (string | number)[],
|
|
71
|
+
keyField: string,
|
|
72
|
+
key: string,
|
|
73
|
+
): YAMLMap | undefined {
|
|
74
|
+
const node = doc.getIn(path, true);
|
|
75
|
+
if (!isSeq(node)) return undefined;
|
|
76
|
+
return node.items.find((it): it is YAMLMap => isMap(it) && String(it.get(keyField)) === String(key));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** True when a map keyed by `keyField === key` already exists in the seq at `path`. */
|
|
80
|
+
export function seqItemExists(doc: Document, path: (string | number)[], keyField: string, key: string): boolean {
|
|
81
|
+
return !!findSeqItemByKey(doc, path, keyField, key);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface UpsertOptions {
|
|
85
|
+
/** When the item already exists: merge `item`'s fields into it. Default false → leave it untouched. */
|
|
86
|
+
overwrite?: boolean;
|
|
87
|
+
/** A `# comment` attached above the newly created item (ignored when the item already exists). */
|
|
88
|
+
commentBefore?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Idempotent upsert of `item` into the YAMLSeq at `path`, matched by `item[keyField]`.
|
|
93
|
+
* - missing → appended (block style), optional leading comment → 'created'
|
|
94
|
+
* - present & !overwrite → left as-is → 'unchanged'
|
|
95
|
+
* - present & overwrite → each field of `item` is set on the existing map → 'updated'/'unchanged'
|
|
96
|
+
* `undefined` fields in `item` are skipped so callers can pass sparse specs.
|
|
97
|
+
*/
|
|
98
|
+
export function upsertSeqItemByKey(
|
|
99
|
+
doc: Document,
|
|
100
|
+
path: (string | number)[],
|
|
101
|
+
keyField: string,
|
|
102
|
+
item: Record<string, unknown>,
|
|
103
|
+
opts: UpsertOptions = {},
|
|
104
|
+
): UpsertOutcome {
|
|
105
|
+
const seq = ensureSeqAt(doc, path);
|
|
106
|
+
const clean = stripUndefined(item);
|
|
107
|
+
const existing = seq.items.find(
|
|
108
|
+
(it): it is YAMLMap => isMap(it) && String(it.get(keyField)) === String(clean[keyField]),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (!existing) {
|
|
112
|
+
const node = doc.createNode(clean) as YAMLMap;
|
|
113
|
+
if (opts.commentBefore) node.commentBefore = ` ${opts.commentBefore}`;
|
|
114
|
+
// Normalize the container to block style: a config seeded with an empty flow seq (`topics: []`)
|
|
115
|
+
// would otherwise render every appended item inline (`[ { name: ... } ]`). Block is the readable,
|
|
116
|
+
// diff-friendly form the rest of the config uses.
|
|
117
|
+
seq.flow = false;
|
|
118
|
+
node.flow = false;
|
|
119
|
+
seq.add(node);
|
|
120
|
+
return 'created';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!opts.overwrite) return 'unchanged';
|
|
124
|
+
|
|
125
|
+
const before = existing.toString();
|
|
126
|
+
for (const [k, v] of Object.entries(clean)) {
|
|
127
|
+
existing.set(k, doc.createNode(v));
|
|
128
|
+
}
|
|
129
|
+
return existing.toString() === before ? 'unchanged' : 'updated';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Set a scalar (or nested map/seq) at `path`, creating parents. Returns whether the value changed. */
|
|
133
|
+
export function setIn(doc: Document, path: (string | number)[], value: unknown): UpsertOutcome {
|
|
134
|
+
const prev = doc.getIn(path, false);
|
|
135
|
+
const existed = prev !== undefined;
|
|
136
|
+
if (existed && JSON.stringify(prev) === JSON.stringify(value)) return 'unchanged';
|
|
137
|
+
doc.setIn(path, doc.createNode(value));
|
|
138
|
+
return existed ? 'updated' : 'created';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Delete the item keyed by `keyField === key` from the seq at `path`. Returns true when removed. */
|
|
142
|
+
export function deleteSeqItemByKey(
|
|
143
|
+
doc: Document,
|
|
144
|
+
path: (string | number)[],
|
|
145
|
+
keyField: string,
|
|
146
|
+
key: string,
|
|
147
|
+
): boolean {
|
|
148
|
+
const node = doc.getIn(path, true);
|
|
149
|
+
if (!isSeq(node)) return false;
|
|
150
|
+
const idx = node.items.findIndex((it) => isMap(it) && String(it.get(keyField)) === String(key));
|
|
151
|
+
if (idx === -1) return false;
|
|
152
|
+
node.items.splice(idx, 1);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Read a scalar value at `path` (JS value, not the wrapping node). */
|
|
157
|
+
export function getScalar(doc: Document, path: (string | number)[]): unknown {
|
|
158
|
+
return doc.getIn(path, false);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function stripUndefined(obj: Record<string, unknown>): Record<string, unknown> {
|
|
162
|
+
const out: Record<string, unknown> = {};
|
|
163
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
164
|
+
if (v !== undefined) out[k] = v;
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|