atom.io 0.29.3 → 0.29.5

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.
@@ -1,256 +0,0 @@
1
- // ../rel8/junction/src/junction.ts
2
- var Junction = class {
3
- a;
4
- b;
5
- cardinality;
6
- relations = /* @__PURE__ */ new Map();
7
- contents = /* @__PURE__ */ new Map();
8
- isContent;
9
- makeContentKey = (a, b) => `${a}:${b}`;
10
- getRelatedKeys(key) {
11
- return this.relations.get(key);
12
- }
13
- addRelation(a, b) {
14
- let aRelations = this.relations.get(a);
15
- let bRelations = this.relations.get(b);
16
- if (aRelations) {
17
- aRelations.add(b);
18
- } else {
19
- aRelations = /* @__PURE__ */ new Set([b]);
20
- this.relations.set(a, aRelations);
21
- }
22
- if (bRelations) {
23
- bRelations.add(a);
24
- } else {
25
- bRelations = /* @__PURE__ */ new Set([a]);
26
- this.relations.set(b, bRelations);
27
- }
28
- }
29
- deleteRelation(a, b) {
30
- const aRelations = this.relations.get(a);
31
- if (aRelations) {
32
- aRelations.delete(b);
33
- if (aRelations.size === 0) {
34
- this.relations.delete(a);
35
- }
36
- const bRelations = this.relations.get(b);
37
- if (bRelations) {
38
- bRelations.delete(a);
39
- if (bRelations.size === 0) {
40
- this.relations.delete(b);
41
- }
42
- }
43
- }
44
- }
45
- replaceRelationsUnsafely(a, bs) {
46
- this.relations.set(a, new Set(bs));
47
- for (const b of bs) {
48
- const bRelations = /* @__PURE__ */ new Set([a]);
49
- this.relations.set(b, bRelations);
50
- }
51
- }
52
- replaceRelationsSafely(a, bs) {
53
- const aRelationsPrev = this.relations.get(a);
54
- if (aRelationsPrev) {
55
- for (const b of aRelationsPrev) {
56
- const bRelations = this.relations.get(b);
57
- if (bRelations) {
58
- if (bRelations.size === 1) {
59
- this.relations.delete(b);
60
- } else {
61
- bRelations.delete(a);
62
- }
63
- this.contents.delete(this.makeContentKey(a, b));
64
- }
65
- }
66
- }
67
- this.relations.set(a, new Set(bs));
68
- for (const b of bs) {
69
- let bRelations = this.relations.get(b);
70
- if (bRelations) {
71
- bRelations.add(a);
72
- } else {
73
- bRelations = /* @__PURE__ */ new Set([a]);
74
- this.relations.set(b, bRelations);
75
- }
76
- }
77
- }
78
- getContentInternal(contentKey) {
79
- return this.contents.get(contentKey);
80
- }
81
- setContent(contentKey, content) {
82
- this.contents.set(contentKey, content);
83
- }
84
- deleteContent(contentKey) {
85
- this.contents.delete(contentKey);
86
- }
87
- constructor(data, config) {
88
- this.a = data.between[0];
89
- this.b = data.between[1];
90
- this.cardinality = data.cardinality;
91
- if (!config?.externalStore) {
92
- this.relations = new Map(data.relations?.map(([a, b]) => [a, new Set(b)]));
93
- this.contents = new Map(data.contents);
94
- }
95
- this.isContent = config?.isContent ?? null;
96
- if (config?.makeContentKey) {
97
- this.makeContentKey = config.makeContentKey;
98
- }
99
- if (config?.externalStore) {
100
- const externalStore = config.externalStore;
101
- this.has = (a, b) => externalStore.has(a, b);
102
- this.addRelation = (a, b) => {
103
- externalStore.addRelation(a, b);
104
- };
105
- this.deleteRelation = (a, b) => {
106
- externalStore.deleteRelation(a, b);
107
- };
108
- this.replaceRelationsSafely = (a, bs) => {
109
- externalStore.replaceRelationsSafely(a, bs);
110
- };
111
- this.replaceRelationsUnsafely = (a, bs) => {
112
- externalStore.replaceRelationsUnsafely(a, bs);
113
- };
114
- this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
115
- if (externalStore.getContent) {
116
- this.getContentInternal = (contentKey) => {
117
- return externalStore.getContent(contentKey);
118
- };
119
- this.setContent = (contentKey, content) => {
120
- externalStore.setContent(contentKey, content);
121
- };
122
- this.deleteContent = (contentKey) => {
123
- externalStore.deleteContent(contentKey);
124
- };
125
- }
126
- for (const [x, ys] of data.relations ?? []) {
127
- for (const y of ys) this.addRelation(x, y);
128
- }
129
- for (const [contentKey, content] of data.contents ?? []) {
130
- this.setContent(contentKey, content);
131
- }
132
- }
133
- }
134
- toJSON() {
135
- return {
136
- between: [this.a, this.b],
137
- cardinality: this.cardinality,
138
- relations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),
139
- contents: [...this.contents.entries()]
140
- };
141
- }
142
- set(a, ...rest) {
143
- const b = typeof rest[0] === `string` ? rest[0] : a[this.b];
144
- const content = rest[1] ?? typeof rest[0] === `string` ? void 0 : rest[0];
145
- a = typeof a === `string` ? a : a[this.a];
146
- switch (this.cardinality) {
147
- // biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here
148
- case `1:1`: {
149
- const bPrev = this.getRelatedKey(a);
150
- if (bPrev && bPrev !== b) this.delete(bPrev, a);
151
- }
152
- case `1:n`: {
153
- const aPrev = this.getRelatedKey(b);
154
- if (aPrev && aPrev !== a) this.delete(aPrev, b);
155
- }
156
- }
157
- if (content) {
158
- const contentKey = this.makeContentKey(a, b);
159
- this.setContent(contentKey, content);
160
- }
161
- this.addRelation(a, b);
162
- return this;
163
- }
164
- delete(x, b) {
165
- b = typeof b === `string` ? b : x[this.b];
166
- const a = typeof x === `string` ? x : x[this.a];
167
- if (a === void 0 && typeof b === `string`) {
168
- const bRelations = this.getRelatedKeys(b);
169
- if (bRelations) {
170
- for (const bRelation of bRelations) {
171
- this.delete(bRelation, b);
172
- }
173
- }
174
- }
175
- if (typeof a === `string` && b === void 0) {
176
- const aRelations = this.getRelatedKeys(a);
177
- if (aRelations) {
178
- for (const aRelation of aRelations) {
179
- this.delete(a, aRelation);
180
- }
181
- }
182
- }
183
- if (typeof a === `string` && typeof b === `string`) {
184
- this.deleteRelation(a, b);
185
- const contentKey = this.makeContentKey(a, b);
186
- this.deleteContent(contentKey);
187
- }
188
- return this;
189
- }
190
- getRelatedKey(key) {
191
- const relations = this.getRelatedKeys(key);
192
- if (relations) {
193
- if (relations.size > 1) {
194
- console.warn(
195
- `${relations.size} related keys were found for key "${key}": (${[
196
- ...relations
197
- ].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
198
- );
199
- }
200
- for (const relation of relations) {
201
- return relation;
202
- }
203
- }
204
- }
205
- replaceRelations(a, relations, config) {
206
- const hasContent = !Array.isArray(relations);
207
- const bs = hasContent ? Object.keys(relations) : relations;
208
- if (config?.reckless) {
209
- this.replaceRelationsUnsafely(a, bs);
210
- } else {
211
- this.replaceRelationsSafely(a, bs);
212
- }
213
- if (hasContent) {
214
- for (const b of bs) {
215
- const contentKey = this.makeContentKey(a, b);
216
- const content = relations[b];
217
- this.setContent(contentKey, content);
218
- }
219
- }
220
- return this;
221
- }
222
- getContent(a, b) {
223
- const contentKey = this.makeContentKey(a, b);
224
- return this.getContentInternal(contentKey);
225
- }
226
- getRelationEntries(input) {
227
- const a = input[this.a];
228
- const b = input[this.b];
229
- if (a !== void 0 && b === void 0) {
230
- const aRelations = this.getRelatedKeys(a);
231
- if (aRelations) {
232
- return [...aRelations].map((aRelation) => {
233
- return [aRelation, this.getContent(a, aRelation) ?? null];
234
- });
235
- }
236
- }
237
- if (a === void 0 && b !== void 0) {
238
- const bRelations = this.getRelatedKeys(b);
239
- if (bRelations) {
240
- return [...bRelations].map((bRelation) => {
241
- return [bRelation, this.getContent(bRelation, b) ?? null];
242
- });
243
- }
244
- }
245
- return [];
246
- }
247
- has(a, b) {
248
- if (b) {
249
- const setA = this.getRelatedKeys(a);
250
- return setA?.has(b) ?? false;
251
- }
252
- return this.relations.has(a);
253
- }
254
- };
255
-
256
- export { Junction };