atom.io 0.30.0 → 0.30.2
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/data/dist/index.d.ts +84 -51
- package/data/dist/index.js +45 -39
- package/data/src/join.ts +250 -142
- package/dist/chunk-ADMEAXYU.js +167 -0
- package/dist/{chunk-7PUUHSXC.js → chunk-LSCRHXLI.js} +67 -176
- package/dist/index.d.ts +53 -5
- package/dist/index.js +1 -1
- package/internal/dist/index.d.ts +64 -35
- package/internal/dist/index.js +2 -2
- package/internal/src/junction.ts +170 -86
- package/internal/src/molecule/make-molecule-in-store.ts +3 -1
- package/internal/src/molecule/molecule-internal.ts +1 -1
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/get-json-family.ts +2 -2
- package/internal/src/store/store.ts +4 -0
- package/internal/src/transaction/index.ts +1 -1
- package/json/dist/index.js +2 -2
- package/package.json +15 -15
- package/realtime/dist/index.d.ts +1 -1
- package/realtime/dist/index.js +3 -1
- package/realtime/src/shared-room-store.ts +2 -0
- package/realtime-server/dist/index.d.ts +15 -6
- package/realtime-server/dist/index.js +4 -2
- package/realtime-server/src/realtime-continuity-synchronizer.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +21 -5
- package/realtime-testing/dist/index.d.ts +3 -0
- package/realtime-testing/dist/index.js +17 -6
- package/realtime-testing/src/setup-realtime-test.tsx +16 -6
- package/src/allocate.ts +7 -8
- package/src/index.ts +1 -0
- package/src/molecule.ts +5 -3
- package/dist/chunk-ZKG6ZA4I.js +0 -20
package/internal/src/junction.ts
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
import type { Refinement } from "atom.io/introspection"
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
extends
|
|
6
|
-
|
|
4
|
+
export type JunctionEntriesBase<
|
|
5
|
+
AType extends string,
|
|
6
|
+
BType extends string,
|
|
7
|
+
Content extends Json.Object | null,
|
|
8
|
+
> = {
|
|
9
|
+
readonly relations: ([AType, BType[]] | [BType, AType[]])[]
|
|
7
10
|
readonly contents: [string, Content][]
|
|
8
11
|
}
|
|
9
|
-
export interface
|
|
10
|
-
extends
|
|
12
|
+
export interface JunctionEntries<
|
|
13
|
+
AType extends string,
|
|
14
|
+
BType extends string,
|
|
15
|
+
Content extends Json.Object | null,
|
|
16
|
+
> extends Json.Object,
|
|
17
|
+
JunctionEntriesBase<AType, BType, Content> {}
|
|
18
|
+
|
|
19
|
+
export type JunctionSchemaBase<ASide extends string, BSide extends string> = {
|
|
11
20
|
readonly between: [a: ASide, b: BSide]
|
|
12
21
|
readonly cardinality: `1:1` | `1:n` | `n:n`
|
|
13
22
|
}
|
|
23
|
+
export interface JunctionSchema<ASide extends string, BSide extends string>
|
|
24
|
+
extends Json.Object,
|
|
25
|
+
JunctionSchemaBase<ASide, BSide> {}
|
|
14
26
|
|
|
15
27
|
export type BaseExternalStoreConfiguration = {
|
|
16
28
|
addRelation: (a: string, b: string) => void
|
|
17
29
|
deleteRelation: (a: string, b: string) => void
|
|
18
30
|
replaceRelationsSafely: (a: string, bs: string[]) => void
|
|
19
31
|
replaceRelationsUnsafely: (a: string, bs: string[]) => void
|
|
20
|
-
getRelatedKeys
|
|
32
|
+
getRelatedKeys(key: string): Set<string> | undefined
|
|
21
33
|
has: (a: string, b?: string) => boolean
|
|
22
34
|
}
|
|
23
35
|
|
|
@@ -39,41 +51,58 @@ export type ExternalStoreConfiguration<Content extends Json.Object | null> =
|
|
|
39
51
|
: BaseExternalStoreConfiguration &
|
|
40
52
|
Empty<ExternalStoreWithContentConfiguration<Json.Object>>
|
|
41
53
|
|
|
42
|
-
export type JunctionAdvancedConfiguration<
|
|
54
|
+
export type JunctionAdvancedConfiguration<
|
|
55
|
+
AType extends string,
|
|
56
|
+
BType extends string,
|
|
57
|
+
Content extends Json.Object | null,
|
|
58
|
+
> = {
|
|
43
59
|
warn?: (...args: any[]) => void
|
|
44
60
|
externalStore?: ExternalStoreConfiguration<Content>
|
|
61
|
+
isAType?: Refinement<string, AType>
|
|
62
|
+
isBType?: Refinement<string, BType>
|
|
45
63
|
isContent?: Refinement<unknown, Content>
|
|
46
|
-
makeContentKey?: (a:
|
|
64
|
+
makeContentKey?: (a: AType, b: BType) => string
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
export type JunctionJSON<
|
|
50
68
|
ASide extends string,
|
|
69
|
+
AType extends string,
|
|
51
70
|
BSide extends string,
|
|
71
|
+
BType extends string,
|
|
52
72
|
Content extends Json.Object | null,
|
|
53
|
-
> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>
|
|
73
|
+
> = JunctionEntries<AType, BType, Content> & JunctionSchema<ASide, BSide>
|
|
54
74
|
|
|
55
75
|
export class Junction<
|
|
56
76
|
const ASide extends string,
|
|
77
|
+
const AType extends string,
|
|
57
78
|
const BSide extends string,
|
|
79
|
+
const BType extends string,
|
|
58
80
|
const Content extends Json.Object | null = null,
|
|
59
81
|
> {
|
|
60
82
|
public readonly a: ASide
|
|
61
83
|
public readonly b: BSide
|
|
62
84
|
public readonly cardinality: `1:1` | `1:n` | `n:n`
|
|
63
|
-
public readonly relations = new Map<
|
|
85
|
+
public readonly relations = new Map<AType | BType, Set<AType> | Set<BType>>()
|
|
64
86
|
public readonly contents = new Map<string, Content>()
|
|
65
87
|
|
|
88
|
+
public isAType?: Refinement<string, AType> | null
|
|
89
|
+
public isBType?: Refinement<string, BType> | null
|
|
66
90
|
public isContent: Refinement<unknown, Content> | null
|
|
67
|
-
public makeContentKey = (a:
|
|
91
|
+
public makeContentKey = (a: AType, b: BType): string => `${a}:${b}`
|
|
68
92
|
|
|
69
93
|
public warn?: (...args: any[]) => void
|
|
70
94
|
|
|
71
|
-
public getRelatedKeys(key:
|
|
95
|
+
public getRelatedKeys(key: AType): Set<BType> | undefined
|
|
96
|
+
public getRelatedKeys(key: BType): Set<AType> | undefined
|
|
97
|
+
public getRelatedKeys(key: AType | BType): Set<AType> | Set<BType> | undefined
|
|
98
|
+
public getRelatedKeys(
|
|
99
|
+
key: AType | BType,
|
|
100
|
+
): Set<AType> | Set<BType> | undefined {
|
|
72
101
|
return this.relations.get(key)
|
|
73
102
|
}
|
|
74
|
-
protected addRelation(a:
|
|
75
|
-
let aRelations = this.relations.get(a)
|
|
76
|
-
let bRelations = this.relations.get(b)
|
|
103
|
+
protected addRelation(a: AType, b: BType): void {
|
|
104
|
+
let aRelations = this.relations.get(a) as Set<BType> | undefined
|
|
105
|
+
let bRelations = this.relations.get(b) as Set<AType> | undefined
|
|
77
106
|
if (aRelations) {
|
|
78
107
|
aRelations.add(b)
|
|
79
108
|
} else {
|
|
@@ -87,14 +116,14 @@ export class Junction<
|
|
|
87
116
|
this.relations.set(b, bRelations)
|
|
88
117
|
}
|
|
89
118
|
}
|
|
90
|
-
protected deleteRelation(a:
|
|
91
|
-
const aRelations = this.relations.get(a)
|
|
119
|
+
protected deleteRelation(a: AType, b: BType): void {
|
|
120
|
+
const aRelations = this.relations.get(a) as Set<BType> | undefined
|
|
92
121
|
if (aRelations) {
|
|
93
122
|
aRelations.delete(b)
|
|
94
123
|
if (aRelations.size === 0) {
|
|
95
124
|
this.relations.delete(a)
|
|
96
125
|
}
|
|
97
|
-
const bRelations = this.relations.get(b)
|
|
126
|
+
const bRelations = this.relations.get(b) as Set<AType> | undefined
|
|
98
127
|
if (bRelations) {
|
|
99
128
|
bRelations.delete(a)
|
|
100
129
|
if (bRelations.size === 0) {
|
|
@@ -104,36 +133,50 @@ export class Junction<
|
|
|
104
133
|
}
|
|
105
134
|
}
|
|
106
135
|
|
|
107
|
-
protected replaceRelationsUnsafely(a:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
136
|
+
protected replaceRelationsUnsafely(a: AType, bs: BType[]): void
|
|
137
|
+
protected replaceRelationsUnsafely(b: BType, as: AType[]): void
|
|
138
|
+
protected replaceRelationsUnsafely(
|
|
139
|
+
x: AType | BType,
|
|
140
|
+
ys: AType[] | BType[],
|
|
141
|
+
): void {
|
|
142
|
+
this.relations.set(x as AType, new Set(ys as BType[]))
|
|
143
|
+
for (const y of ys) {
|
|
144
|
+
const yRelations = new Set<AType>().add(x as AType)
|
|
145
|
+
this.relations.set(y, yRelations)
|
|
112
146
|
}
|
|
113
147
|
}
|
|
114
|
-
protected replaceRelationsSafely(a:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
protected replaceRelationsSafely(a: AType, bs: BType[]): void
|
|
149
|
+
protected replaceRelationsSafely(b: BType, as: AType[]): void
|
|
150
|
+
protected replaceRelationsSafely<
|
|
151
|
+
XType extends AType | BType,
|
|
152
|
+
YType extends XType extends AType ? BType : AType,
|
|
153
|
+
>(x: XType, ys: YType[]): void {
|
|
154
|
+
const xRelationsPrev = this.relations.get(x)
|
|
155
|
+
let a: AType | undefined = this.isAType?.(x) ? x : undefined
|
|
156
|
+
let b: BType | undefined = a === undefined ? (x as BType) : undefined
|
|
157
|
+
if (xRelationsPrev) {
|
|
158
|
+
for (const y of xRelationsPrev) {
|
|
159
|
+
a ??= y as AType
|
|
160
|
+
b ??= y as BType
|
|
161
|
+
const yRelations = this.relations.get(y) as Set<XType> | undefined
|
|
162
|
+
if (yRelations) {
|
|
163
|
+
if (yRelations.size === 1) {
|
|
164
|
+
this.relations.delete(y)
|
|
122
165
|
} else {
|
|
123
|
-
|
|
166
|
+
yRelations.delete(x)
|
|
124
167
|
}
|
|
125
168
|
this.contents.delete(this.makeContentKey(a, b))
|
|
126
169
|
}
|
|
127
170
|
}
|
|
128
171
|
}
|
|
129
|
-
this.relations.set(
|
|
130
|
-
for (const
|
|
131
|
-
let
|
|
132
|
-
if (
|
|
133
|
-
|
|
172
|
+
this.relations.set(x, new Set(ys) as any)
|
|
173
|
+
for (const y of ys) {
|
|
174
|
+
let yRelations = this.relations.get(y) as Set<XType> | undefined
|
|
175
|
+
if (yRelations) {
|
|
176
|
+
yRelations.add(x)
|
|
134
177
|
} else {
|
|
135
|
-
|
|
136
|
-
this.relations.set(
|
|
178
|
+
yRelations = new Set<XType>().add(x)
|
|
179
|
+
this.relations.set(y, yRelations as any)
|
|
137
180
|
}
|
|
138
181
|
}
|
|
139
182
|
}
|
|
@@ -149,17 +192,22 @@ export class Junction<
|
|
|
149
192
|
}
|
|
150
193
|
|
|
151
194
|
public constructor(
|
|
152
|
-
data: JunctionSchema<ASide, BSide> &
|
|
153
|
-
|
|
195
|
+
data: JunctionSchema<ASide, BSide> &
|
|
196
|
+
Partial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>,
|
|
197
|
+
config?: JunctionAdvancedConfiguration<AType, BType, Content>,
|
|
154
198
|
) {
|
|
155
199
|
this.a = data.between[0]
|
|
156
200
|
this.b = data.between[1]
|
|
157
201
|
|
|
158
202
|
this.cardinality = data.cardinality
|
|
159
203
|
if (!config?.externalStore) {
|
|
160
|
-
this.relations = new Map(
|
|
204
|
+
this.relations = new Map(
|
|
205
|
+
data.relations?.map(([x, ys]) => [x, new Set(ys as AType[])]),
|
|
206
|
+
)
|
|
161
207
|
this.contents = new Map(data.contents)
|
|
162
208
|
}
|
|
209
|
+
this.isAType = config?.isAType ?? null
|
|
210
|
+
this.isBType = config?.isBType ?? null
|
|
163
211
|
this.isContent = config?.isContent ?? null
|
|
164
212
|
if (config?.makeContentKey) {
|
|
165
213
|
this.makeContentKey = config.makeContentKey
|
|
@@ -179,7 +227,10 @@ export class Junction<
|
|
|
179
227
|
this.replaceRelationsUnsafely = (a, bs) => {
|
|
180
228
|
externalStore.replaceRelationsUnsafely(a, bs)
|
|
181
229
|
}
|
|
182
|
-
this.getRelatedKeys = (key) =>
|
|
230
|
+
this.getRelatedKeys = ((key) =>
|
|
231
|
+
externalStore.getRelatedKeys(
|
|
232
|
+
key,
|
|
233
|
+
)) as typeof Junction.prototype.getRelatedKeys
|
|
183
234
|
if (externalStore.getContent) {
|
|
184
235
|
this.getContentInternal = (contentKey) => {
|
|
185
236
|
return externalStore.getContent(contentKey) as any
|
|
@@ -192,7 +243,13 @@ export class Junction<
|
|
|
192
243
|
}
|
|
193
244
|
}
|
|
194
245
|
for (const [x, ys] of data.relations ?? []) {
|
|
195
|
-
|
|
246
|
+
let a = this.isAType?.(x) ? x : undefined
|
|
247
|
+
let b = a === undefined ? (x as BType) : undefined
|
|
248
|
+
for (const y of ys) {
|
|
249
|
+
a ??= y as AType
|
|
250
|
+
b ??= y as BType
|
|
251
|
+
this.addRelation(a, b)
|
|
252
|
+
}
|
|
196
253
|
}
|
|
197
254
|
for (const [contentKey, content] of data.contents ?? []) {
|
|
198
255
|
this.setContent(contentKey, content)
|
|
@@ -202,33 +259,35 @@ export class Junction<
|
|
|
202
259
|
this.warn = config.warn
|
|
203
260
|
}
|
|
204
261
|
}
|
|
205
|
-
public toJSON(): JunctionJSON<ASide, BSide, Content> {
|
|
262
|
+
public toJSON(): JunctionJSON<ASide, AType, BSide, BType, Content> {
|
|
206
263
|
return {
|
|
207
264
|
between: [this.a, this.b],
|
|
208
265
|
cardinality: this.cardinality,
|
|
209
|
-
relations: [...this.relations.entries()].map(
|
|
266
|
+
relations: [...this.relations.entries()].map(
|
|
267
|
+
([a, b]) => [a, [...b]] as [AType, BType[]],
|
|
268
|
+
),
|
|
210
269
|
contents: [...this.contents.entries()],
|
|
211
270
|
}
|
|
212
271
|
}
|
|
213
272
|
|
|
214
273
|
public set(
|
|
215
|
-
a:
|
|
216
|
-
...rest: Content extends null ? [b:
|
|
274
|
+
a: AType,
|
|
275
|
+
...rest: Content extends null ? [b: BType] : [b: BType, content: Content]
|
|
217
276
|
): this
|
|
218
277
|
public set(
|
|
219
|
-
relation: { [Key in ASide
|
|
220
|
-
...rest: Content extends null ? [] | [
|
|
278
|
+
relation: { [Key in ASide]: AType } & { [Key in BSide]: BType },
|
|
279
|
+
...rest: Content extends null ? [] | [void?: undefined] : [content: Content]
|
|
221
280
|
): this
|
|
222
281
|
public set(
|
|
223
|
-
a:
|
|
282
|
+
a: AType | ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),
|
|
224
283
|
...rest: Content extends null
|
|
225
|
-
? [] | [b?:
|
|
226
|
-
: [b:
|
|
284
|
+
? [] | [b?: BType | undefined]
|
|
285
|
+
: [b: BType, content: Content] | [content: Content]
|
|
227
286
|
): this {
|
|
228
|
-
const b:
|
|
287
|
+
const b: BType =
|
|
229
288
|
typeof rest[0] === `string`
|
|
230
289
|
? rest[0]
|
|
231
|
-
: (a[this.b as keyof typeof a] as
|
|
290
|
+
: (a[this.b as keyof typeof a] as BType)
|
|
232
291
|
const content: Content | undefined =
|
|
233
292
|
(rest[1] ?? typeof rest[0] === `string`) ? undefined : (rest[0] as Content)
|
|
234
293
|
a = typeof a === `string` ? a : a[this.a]
|
|
@@ -236,7 +295,7 @@ export class Junction<
|
|
|
236
295
|
// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here
|
|
237
296
|
case `1:1`: {
|
|
238
297
|
const bPrev = this.getRelatedKey(a)
|
|
239
|
-
if (bPrev && bPrev !== b) this.delete(
|
|
298
|
+
if (bPrev && bPrev !== b) this.delete(a, bPrev)
|
|
240
299
|
}
|
|
241
300
|
case `1:n`: {
|
|
242
301
|
const aPrev = this.getRelatedKey(b)
|
|
@@ -251,29 +310,32 @@ export class Junction<
|
|
|
251
310
|
return this
|
|
252
311
|
}
|
|
253
312
|
|
|
254
|
-
public delete(a:
|
|
313
|
+
public delete(a: AType, b?: BType): this
|
|
314
|
+
public delete(b: BType, a?: AType): this
|
|
255
315
|
public delete(
|
|
256
316
|
relation:
|
|
257
|
-
|
|
|
258
|
-
|
|
|
259
|
-
|
|
|
317
|
+
| { [Key in ASide]: AType }
|
|
318
|
+
| { [Key in BSide]: BType }
|
|
319
|
+
| ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),
|
|
260
320
|
b?: undefined,
|
|
261
321
|
): this
|
|
262
322
|
public delete(
|
|
263
323
|
x:
|
|
324
|
+
| AType
|
|
325
|
+
| BType
|
|
264
326
|
| Record<ASide | BSide, string>
|
|
265
327
|
| Record<ASide, string>
|
|
266
|
-
| Record<BSide, string
|
|
267
|
-
|
|
268
|
-
b?: string,
|
|
328
|
+
| Record<BSide, string>,
|
|
329
|
+
b?: AType | BType,
|
|
269
330
|
): this {
|
|
270
331
|
// @ts-expect-error we deduce that this.b may index x
|
|
271
|
-
b = typeof b === `string` ? b : (x[this.b] as
|
|
272
|
-
|
|
273
|
-
|
|
332
|
+
b = typeof b === `string` ? (b as BType) : (x[this.b] as BType | undefined)
|
|
333
|
+
const a =
|
|
334
|
+
// @ts-expect-error we deduce that this.a may index x
|
|
335
|
+
typeof x === `string` ? (x as AType) : (x[this.a] as AType | undefined)
|
|
274
336
|
|
|
275
337
|
if (a === undefined && typeof b === `string`) {
|
|
276
|
-
const bRelations = this.getRelatedKeys(b)
|
|
338
|
+
const bRelations = this.getRelatedKeys(b) as Set<AType>
|
|
277
339
|
if (bRelations) {
|
|
278
340
|
for (const bRelation of bRelations) {
|
|
279
341
|
this.delete(bRelation, b)
|
|
@@ -296,7 +358,9 @@ export class Junction<
|
|
|
296
358
|
return this
|
|
297
359
|
}
|
|
298
360
|
|
|
299
|
-
public getRelatedKey(key:
|
|
361
|
+
public getRelatedKey(key: AType): BType | undefined
|
|
362
|
+
public getRelatedKey(key: BType): AType | undefined
|
|
363
|
+
public getRelatedKey(key: AType | BType): AType | BType | undefined {
|
|
300
364
|
const relations = this.getRelatedKeys(key)
|
|
301
365
|
if (relations) {
|
|
302
366
|
if (relations.size > 1) {
|
|
@@ -308,49 +372,67 @@ export class Junction<
|
|
|
308
372
|
.join(`, `)}). Only one related key was expected.`,
|
|
309
373
|
)
|
|
310
374
|
}
|
|
375
|
+
let singleRelation: AType | BType | undefined
|
|
311
376
|
for (const relation of relations) {
|
|
312
|
-
|
|
377
|
+
singleRelation = relation
|
|
378
|
+
break
|
|
313
379
|
}
|
|
380
|
+
return singleRelation
|
|
314
381
|
}
|
|
315
382
|
}
|
|
316
383
|
|
|
317
384
|
public replaceRelations(
|
|
318
|
-
a:
|
|
319
|
-
relations: Content extends null ?
|
|
385
|
+
a: AType,
|
|
386
|
+
relations: Content extends null ? BType[] : Record<BType, Content>,
|
|
387
|
+
config?: { reckless: boolean },
|
|
388
|
+
): this
|
|
389
|
+
public replaceRelations(
|
|
390
|
+
b: BType,
|
|
391
|
+
relations: Content extends null ? AType[] : Record<AType, Content>,
|
|
392
|
+
config?: { reckless: boolean },
|
|
393
|
+
): this
|
|
394
|
+
public replaceRelations<
|
|
395
|
+
XType extends AType | BType,
|
|
396
|
+
YType extends XType extends AType ? BType : AType,
|
|
397
|
+
>(
|
|
398
|
+
x: XType,
|
|
399
|
+
relations: Content extends null ? YType[] : Record<YType, Content>,
|
|
320
400
|
config?: { reckless: boolean },
|
|
321
401
|
): this {
|
|
322
402
|
const hasContent = !Array.isArray(relations)
|
|
323
|
-
const
|
|
403
|
+
const ys = (hasContent ? Object.keys(relations) : relations) as YType[]
|
|
324
404
|
if (config?.reckless) {
|
|
325
|
-
this.replaceRelationsUnsafely(
|
|
405
|
+
this.replaceRelationsUnsafely(x as any, ys as any)
|
|
326
406
|
} else {
|
|
327
|
-
this.replaceRelationsSafely(
|
|
407
|
+
this.replaceRelationsSafely(x as any, ys as any)
|
|
328
408
|
}
|
|
329
409
|
if (hasContent) {
|
|
330
|
-
for (const
|
|
331
|
-
const contentKey = this.makeContentKey(
|
|
332
|
-
const content = relations
|
|
410
|
+
for (const y of ys) {
|
|
411
|
+
const contentKey = this.makeContentKey(x as any, y as any) // sort XY to AB ❗
|
|
412
|
+
const content = (relations as Record<YType, Content>)[y]
|
|
333
413
|
this.setContent(contentKey, content)
|
|
334
414
|
}
|
|
335
415
|
}
|
|
336
416
|
return this
|
|
337
417
|
}
|
|
338
418
|
|
|
339
|
-
public getContent(a:
|
|
419
|
+
public getContent(a: AType, b: BType): Content | undefined {
|
|
340
420
|
const contentKey = this.makeContentKey(a, b)
|
|
341
421
|
return this.getContentInternal(contentKey)
|
|
342
422
|
}
|
|
343
423
|
|
|
424
|
+
public getRelationEntries(input: Record<ASide, AType>): [BType, Content][]
|
|
425
|
+
public getRelationEntries(input: Record<BSide, BType>): [AType, Content][]
|
|
344
426
|
public getRelationEntries(
|
|
345
|
-
input: Record<ASide,
|
|
346
|
-
): [
|
|
347
|
-
const a:
|
|
348
|
-
const b:
|
|
427
|
+
input: Record<ASide, AType> | Record<BSide, BType>,
|
|
428
|
+
): [AType | BType, Content][] {
|
|
429
|
+
const a: AType | undefined = (input as any)[this.a]
|
|
430
|
+
const b: BType | undefined = (input as any)[this.b]
|
|
349
431
|
if (a !== undefined && b === undefined) {
|
|
350
432
|
const aRelations = this.getRelatedKeys(a)
|
|
351
433
|
if (aRelations) {
|
|
352
434
|
return [...aRelations].map((aRelation) => {
|
|
353
|
-
return [aRelation, this.getContent(a, aRelation)
|
|
435
|
+
return [aRelation, this.getContent(a, aRelation) as Content]
|
|
354
436
|
})
|
|
355
437
|
}
|
|
356
438
|
}
|
|
@@ -358,17 +440,19 @@ export class Junction<
|
|
|
358
440
|
const bRelations = this.getRelatedKeys(b)
|
|
359
441
|
if (bRelations) {
|
|
360
442
|
return [...bRelations].map((bRelation) => {
|
|
361
|
-
return [bRelation, this.getContent(bRelation, b)
|
|
443
|
+
return [bRelation, this.getContent(bRelation, b) as Content]
|
|
362
444
|
})
|
|
363
445
|
}
|
|
364
446
|
}
|
|
365
447
|
return []
|
|
366
448
|
}
|
|
367
449
|
|
|
368
|
-
public has(a:
|
|
450
|
+
public has(a: AType, b?: BType): boolean
|
|
451
|
+
public has(b: BType, a?: AType): boolean
|
|
452
|
+
public has(a: AType | BType, b?: AType | BType): boolean {
|
|
369
453
|
if (b) {
|
|
370
454
|
const setA = this.getRelatedKeys(a)
|
|
371
|
-
return setA?.has(b) ?? false
|
|
455
|
+
return setA?.has(b as any) ?? false
|
|
372
456
|
}
|
|
373
457
|
return this.relations.has(a)
|
|
374
458
|
}
|
|
@@ -82,7 +82,9 @@ export function makeMoleculeInStore<M extends MoleculeConstructor>(
|
|
|
82
82
|
},
|
|
83
83
|
env: () => getEnvironmentData(newest(rootStore)),
|
|
84
84
|
bond: ((
|
|
85
|
-
token:
|
|
85
|
+
token:
|
|
86
|
+
| JoinToken<any, any, any, any, any, any>
|
|
87
|
+
| ReadableFamilyToken<any, any>,
|
|
86
88
|
maybeRole,
|
|
87
89
|
) => {
|
|
88
90
|
if (token.type === `join`) {
|
|
@@ -31,7 +31,7 @@ export class Molecule<M extends MoleculeConstructor>
|
|
|
31
31
|
public tokens = new Map<string, ReadableToken<any>>()
|
|
32
32
|
public above = new Map<string, Molecule<any>>()
|
|
33
33
|
public below = new Map<string, Molecule<any>>()
|
|
34
|
-
public joins = new Map<string, Join<any, any, any, any>>()
|
|
34
|
+
public joins = new Map<string, Join<any, any, any, any, any, any>>()
|
|
35
35
|
public instance: InstanceType<M>
|
|
36
36
|
public constructor(
|
|
37
37
|
ctx: Molecule<any>[] | undefined,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
StateCreation,
|
|
8
8
|
StateDisposal,
|
|
9
9
|
} from "atom.io"
|
|
10
|
-
import type { Json } from "atom.io/json"
|
|
10
|
+
import type { Canonical, Json } from "atom.io/json"
|
|
11
11
|
import { selectJsonFamily, stringifyJson } from "atom.io/json"
|
|
12
12
|
|
|
13
13
|
import { type MutableAtomFamily, prettyPrintTokenType } from ".."
|
|
@@ -21,7 +21,7 @@ import type { Transceiver } from "./transceiver"
|
|
|
21
21
|
export function createMutableAtomFamily<
|
|
22
22
|
T extends Transceiver<any>,
|
|
23
23
|
J extends Json.Serializable,
|
|
24
|
-
K extends
|
|
24
|
+
K extends Canonical,
|
|
25
25
|
>(
|
|
26
26
|
store: Store,
|
|
27
27
|
options: MutableAtomFamilyOptions<T, J, K>,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MutableAtomFamilyToken } from "atom.io"
|
|
2
|
-
import type { Json } from "atom.io/json"
|
|
2
|
+
import type { Canonical, Json } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { WritableSelectorFamily } from ".."
|
|
5
5
|
import { newest } from "../lineage"
|
|
@@ -9,7 +9,7 @@ import type { Transceiver } from "./transceiver"
|
|
|
9
9
|
export const getJsonFamily = <
|
|
10
10
|
Core extends Transceiver<Json.Serializable>,
|
|
11
11
|
SerializableCore extends Json.Serializable,
|
|
12
|
-
Key extends
|
|
12
|
+
Key extends Canonical,
|
|
13
13
|
>(
|
|
14
14
|
mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,
|
|
15
15
|
store: Store,
|
|
@@ -56,7 +56,9 @@ export class Store implements Lineage {
|
|
|
56
56
|
})
|
|
57
57
|
public selectorGraph = new Junction<
|
|
58
58
|
`upstreamSelectorKey`,
|
|
59
|
+
string,
|
|
59
60
|
`downstreamSelectorKey`,
|
|
61
|
+
string,
|
|
60
62
|
{ source: string }
|
|
61
63
|
>(
|
|
62
64
|
{
|
|
@@ -88,7 +90,9 @@ export class Store implements Lineage {
|
|
|
88
90
|
public timelines = new Map<string, Timeline<any>>()
|
|
89
91
|
public timelineTopics = new Junction<
|
|
90
92
|
`timelineKey`,
|
|
93
|
+
string,
|
|
91
94
|
`topicKey`,
|
|
95
|
+
string,
|
|
92
96
|
{ topicType: `atom_family` | `atom` | `molecule_family` | `molecule` }
|
|
93
97
|
>({
|
|
94
98
|
between: [`timelineKey`, `topicKey`],
|
package/json/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createWritableSelectorFamily } from '../../dist/chunk-
|
|
2
|
-
import '../../dist/chunk-
|
|
1
|
+
import { createWritableSelectorFamily } from '../../dist/chunk-LSCRHXLI.js';
|
|
2
|
+
import '../../dist/chunk-ADMEAXYU.js';
|
|
3
3
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
4
4
|
import { createStandaloneSelector, IMPLICIT, growMoleculeInStore, initFamilyMemberInStore, withdraw, seekInStore } from 'atom.io/internal';
|
|
5
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.2",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -57,34 +57,34 @@
|
|
|
57
57
|
"@types/estree": "1.0.6",
|
|
58
58
|
"@types/http-proxy": "1.17.15",
|
|
59
59
|
"@types/npmlog": "7.0.0",
|
|
60
|
-
"@types/react": "18.3.
|
|
60
|
+
"@types/react": "18.3.12",
|
|
61
61
|
"@types/tmp": "0.2.6",
|
|
62
|
-
"@typescript-eslint/parser": "8.
|
|
63
|
-
"@typescript-eslint/rule-tester": "8.
|
|
64
|
-
"@vitest/coverage-v8": "2.1.
|
|
65
|
-
"@vitest/ui": "2.1.
|
|
62
|
+
"@typescript-eslint/parser": "8.10.0",
|
|
63
|
+
"@typescript-eslint/rule-tester": "8.10.0",
|
|
64
|
+
"@vitest/coverage-v8": "2.1.3",
|
|
65
|
+
"@vitest/ui": "2.1.3",
|
|
66
66
|
"concurrently": "9.0.1",
|
|
67
|
-
"drizzle-kit": "0.
|
|
68
|
-
"drizzle-orm": "0.
|
|
69
|
-
"eslint": "9.
|
|
70
|
-
"framer-motion": "11.11.
|
|
67
|
+
"drizzle-kit": "0.26.2",
|
|
68
|
+
"drizzle-orm": "0.35.3",
|
|
69
|
+
"eslint": "9.13.0",
|
|
70
|
+
"framer-motion": "11.11.9",
|
|
71
71
|
"happy-dom": "15.7.4",
|
|
72
72
|
"http-proxy": "1.18.1",
|
|
73
73
|
"npmlog": "7.0.1",
|
|
74
74
|
"postgres": "3.4.4",
|
|
75
|
-
"preact": "10.24.
|
|
75
|
+
"preact": "10.24.3",
|
|
76
76
|
"react": "18.3.1",
|
|
77
77
|
"react-dom": "18.3.1",
|
|
78
|
-
"react-router-dom": "6.
|
|
78
|
+
"react-router-dom": "6.27.0",
|
|
79
79
|
"socket.io": "4.8.0",
|
|
80
80
|
"socket.io-client": "4.8.0",
|
|
81
81
|
"tmp": "0.2.3",
|
|
82
82
|
"tsup": "8.3.0",
|
|
83
83
|
"tsx": "4.19.1",
|
|
84
|
-
"typescript": "5.6.
|
|
85
|
-
"vite": "5.4.
|
|
84
|
+
"typescript": "5.6.3",
|
|
85
|
+
"vite": "5.4.10",
|
|
86
86
|
"vite-tsconfig-paths": "5.0.1",
|
|
87
|
-
"vitest": "2.1.
|
|
87
|
+
"vitest": "2.1.3",
|
|
88
88
|
"zod": "3.23.8"
|
|
89
89
|
},
|
|
90
90
|
"main": "dist/index.js",
|
package/realtime/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ type UserInRoomMeta = {
|
|
|
45
45
|
enteredAtEpoch: number;
|
|
46
46
|
};
|
|
47
47
|
declare const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta;
|
|
48
|
-
declare const usersInRooms: atom_io_data.JoinToken<"room", "user", "1:n", UserInRoomMeta>;
|
|
48
|
+
declare const usersInRooms: atom_io_data.JoinToken<"room", string, "user", string, "1:n", UserInRoomMeta>;
|
|
49
49
|
declare const usersInMyRoomView: atom_io.ReadonlySelectorFamilyToken<MutableAtomToken<SetRTX<string>, SetRTXJson<string>>[], string>;
|
|
50
50
|
|
|
51
51
|
export { type ContinuityOptions, type ContinuityToken, DEFAULT_USER_IN_ROOM_META, InvariantMap, type PerspectiveToken, SyncGroup, type UserInRoomMeta, continuity, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
|
package/realtime/dist/index.js
CHANGED
|
@@ -90,7 +90,9 @@ var usersInRooms = join(
|
|
|
90
90
|
{
|
|
91
91
|
key: `usersInRooms`,
|
|
92
92
|
between: [`room`, `user`],
|
|
93
|
-
cardinality: `1:n
|
|
93
|
+
cardinality: `1:n`,
|
|
94
|
+
isAType: (input) => typeof input === `string`,
|
|
95
|
+
isBType: (input) => typeof input === `string`
|
|
94
96
|
},
|
|
95
97
|
DEFAULT_USER_IN_ROOM_META
|
|
96
98
|
);
|
|
@@ -31,6 +31,8 @@ export const usersInRooms = join(
|
|
|
31
31
|
key: `usersInRooms`,
|
|
32
32
|
between: [`room`, `user`],
|
|
33
33
|
cardinality: `1:n`,
|
|
34
|
+
isAType: (input): input is string => typeof input === `string`,
|
|
35
|
+
isBType: (input): input is string => typeof input === `string`,
|
|
34
36
|
},
|
|
35
37
|
DEFAULT_USER_IN_ROOM_META,
|
|
36
38
|
)
|