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.
- package/data/dist/index.d.ts +18 -94
- package/data/dist/index.js +1 -2
- package/data/src/join.ts +13 -14
- package/dist/{chunk-HH7WBSVS.js → chunk-TCINPEYE.js} +260 -2
- package/internal/dist/index.d.ts +58 -67
- package/internal/dist/index.js +1 -2
- package/internal/src/index.ts +1 -0
- package/internal/src/junction.ts +375 -0
- package/internal/src/store/store.ts +4 -6
- package/internal/src/transaction/build-transaction.ts +1 -2
- package/json/dist/index.js +1 -2
- package/package.json +12 -10
- package/realtime-testing/dist/index.d.ts +2 -2
- package/realtime-testing/dist/index.js +6 -6
- package/realtime-testing/src/setup-realtime-test.tsx +8 -9
- package/dist/chunk-IZXKJOQQ.js +0 -256
package/data/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as AtomIO from 'atom.io';
|
|
2
2
|
import { ReadonlySelectorFamilyToken, MutableAtomFamilyToken, SetterToolkit, disposeState, ReadonlySelectorToken } from 'atom.io';
|
|
3
|
-
import { Store, Molecule } from 'atom.io/internal';
|
|
4
|
-
import { Canonical, stringified, Json
|
|
3
|
+
import { Store, JunctionSchema, JunctionEntries, Molecule, Junction } from 'atom.io/internal';
|
|
4
|
+
import { Canonical, stringified, Json } from 'atom.io/json';
|
|
5
5
|
import { findState } from 'atom.io/ephemeral';
|
|
6
6
|
import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
|
|
7
7
|
|
|
@@ -9,94 +9,18 @@ declare function dict<State, Key extends Canonical>(family: AtomIO.ReadonlySelec
|
|
|
9
9
|
[K in stringified<Key>]: State;
|
|
10
10
|
}>;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
declare namespace Json {
|
|
14
|
-
type Serializable = primitive | Readonly<{
|
|
15
|
-
[key: string]: Serializable;
|
|
16
|
-
}> | ReadonlyArray<Serializable>;
|
|
17
|
-
type Object<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
18
|
-
type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
|
|
22
|
-
type Cardinality = `1:1` | `1:n` | `n:n`;
|
|
23
|
-
|
|
24
|
-
interface JunctionEntries<Content extends Json.Object | null> extends Json.Object {
|
|
25
|
-
readonly relations: [string, string[]][];
|
|
26
|
-
readonly contents: [string, Content][];
|
|
27
|
-
}
|
|
28
|
-
interface JunctionSchema<ASide extends string, BSide extends string> extends Json.Object {
|
|
29
|
-
readonly between: [a: ASide, b: BSide];
|
|
30
|
-
readonly cardinality: Cardinality;
|
|
31
|
-
}
|
|
32
|
-
type BaseExternalStoreConfiguration = {
|
|
33
|
-
addRelation: (a: string, b: string) => void;
|
|
34
|
-
deleteRelation: (a: string, b: string) => void;
|
|
35
|
-
replaceRelationsSafely: (a: string, bs: string[]) => void;
|
|
36
|
-
replaceRelationsUnsafely: (a: string, bs: string[]) => void;
|
|
37
|
-
getRelatedKeys: (key: string) => Set<string> | undefined;
|
|
38
|
-
has: (a: string, b?: string) => boolean;
|
|
39
|
-
};
|
|
40
|
-
type ExternalStoreWithContentConfiguration<Content extends Json.Object> = {
|
|
41
|
-
getContent: (contentKey: string) => Content | undefined;
|
|
42
|
-
setContent: (contentKey: string, content: Content) => void;
|
|
43
|
-
deleteContent: (contentKey: string) => void;
|
|
44
|
-
};
|
|
45
|
-
type Empty<Obj extends object> = {
|
|
46
|
-
[Key in keyof Obj]?: undefined;
|
|
47
|
-
};
|
|
48
|
-
type ExternalStoreConfiguration<Content extends Json.Object | null> = Content extends Json.Object ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Json.Object>>;
|
|
49
|
-
type JunctionAdvancedConfiguration<Content extends Json.Object | null> = {
|
|
50
|
-
externalStore?: ExternalStoreConfiguration<Content>;
|
|
51
|
-
isContent?: Refinement<unknown, Content>;
|
|
52
|
-
makeContentKey?: (a: string, b: string) => string;
|
|
53
|
-
};
|
|
54
|
-
type JunctionJSON<ASide extends string, BSide extends string, Content extends Json.Object | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
|
|
55
|
-
declare class Junction<const ASide extends string, const BSide extends string, const Content extends Json.Object | null = null> {
|
|
56
|
-
readonly a: ASide;
|
|
57
|
-
readonly b: BSide;
|
|
58
|
-
readonly cardinality: Cardinality;
|
|
59
|
-
readonly relations: Map<string, Set<string>>;
|
|
60
|
-
readonly contents: Map<string, Content>;
|
|
61
|
-
isContent: Refinement<unknown, Content> | null;
|
|
62
|
-
makeContentKey: (a: string, b: string) => string;
|
|
63
|
-
getRelatedKeys(key: string): Set<string> | undefined;
|
|
64
|
-
protected addRelation(a: string, b: string): void;
|
|
65
|
-
protected deleteRelation(a: string, b: string): void;
|
|
66
|
-
protected replaceRelationsUnsafely(a: string, bs: string[]): void;
|
|
67
|
-
protected replaceRelationsSafely(a: string, bs: string[]): void;
|
|
68
|
-
protected getContentInternal(contentKey: string): Content | undefined;
|
|
69
|
-
protected setContent(contentKey: string, content: Content): void;
|
|
70
|
-
protected deleteContent(contentKey: string): void;
|
|
71
|
-
constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
|
|
72
|
-
toJSON(): JunctionJSON<ASide, BSide, Content>;
|
|
73
|
-
set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
|
|
74
|
-
set(relation: {
|
|
75
|
-
[Key in ASide | BSide]: string;
|
|
76
|
-
}, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
|
|
77
|
-
delete(a: string, b?: string): this;
|
|
78
|
-
delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
|
|
79
|
-
getRelatedKey(key: string): string | undefined;
|
|
80
|
-
replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
|
|
81
|
-
reckless: boolean;
|
|
82
|
-
}): this;
|
|
83
|
-
getContent(a: string, b: string): Content | undefined;
|
|
84
|
-
getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
|
|
85
|
-
has(a: string, b?: string): boolean;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
interface JoinOptions<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json$1.Object | null> extends Json$1.Object, JunctionSchema<ASide, BSide>, Partial<JunctionEntries<Content>> {
|
|
12
|
+
interface JoinOptions<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> extends Json.Object, JunctionSchema<ASide, BSide>, Partial<JunctionEntries<Content>> {
|
|
89
13
|
readonly key: string;
|
|
90
14
|
readonly cardinality: Cardinality;
|
|
91
15
|
}
|
|
92
|
-
type JoinStateFamilies<ASide extends string, BSide extends string, Cardinality extends
|
|
16
|
+
type JoinStateFamilies<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
|
|
93
17
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntryOf${Capitalize<BSide>}` : `${AB}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
|
|
94
18
|
string,
|
|
95
19
|
Content
|
|
96
20
|
] | null, string>;
|
|
97
21
|
} : {}) & {
|
|
98
22
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeyOf${Capitalize<BSide>}` : `${AB}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<string | null, string>;
|
|
99
|
-
} : Cardinality extends `1:n` ? (Content extends Json
|
|
23
|
+
} : Cardinality extends `1:n` ? (Content extends Json.Object ? {
|
|
100
24
|
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
|
|
101
25
|
string,
|
|
102
26
|
Content
|
|
@@ -110,7 +34,7 @@ type JoinStateFamilies<ASide extends string, BSide extends string, Cardinality e
|
|
|
110
34
|
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<string | null, string>;
|
|
111
35
|
} & {
|
|
112
36
|
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<string[], string>;
|
|
113
|
-
} : Cardinality extends `n:n` ? (Content extends Json
|
|
37
|
+
} : Cardinality extends `n:n` ? (Content extends Json.Object ? {
|
|
114
38
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntriesOf${Capitalize<BSide>}` : `${AB}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
|
|
115
39
|
string,
|
|
116
40
|
Content
|
|
@@ -118,7 +42,7 @@ type JoinStateFamilies<ASide extends string, BSide extends string, Cardinality e
|
|
|
118
42
|
} : {}) & {
|
|
119
43
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeysOf${Capitalize<BSide>}` : `${AB}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<string[], string>;
|
|
120
44
|
} : never;
|
|
121
|
-
declare class Join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json
|
|
45
|
+
declare class Join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object | null = null> {
|
|
122
46
|
private options;
|
|
123
47
|
private defaultContent;
|
|
124
48
|
private toolkit;
|
|
@@ -138,7 +62,7 @@ declare class Join<const ASide extends string, const BSide extends string, const
|
|
|
138
62
|
in(store: Store): Join<ASide, BSide, Cardinality, Content>;
|
|
139
63
|
constructor(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content | undefined, store?: Store);
|
|
140
64
|
}
|
|
141
|
-
type JoinToken<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
65
|
+
type JoinToken<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null = null> = {
|
|
142
66
|
key: string;
|
|
143
67
|
type: `join`;
|
|
144
68
|
cardinality: Cardinality;
|
|
@@ -147,19 +71,19 @@ type JoinToken<ASide extends string, BSide extends string, Cardinality extends `
|
|
|
147
71
|
__content?: Content;
|
|
148
72
|
};
|
|
149
73
|
declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`>(options: JoinOptions<ASide, BSide, Cardinality, null>, defaultContent?: undefined, store?: Store): JoinToken<ASide, BSide, Cardinality, null>;
|
|
150
|
-
declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json
|
|
74
|
+
declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): JoinToken<ASide, BSide, Cardinality, Content>;
|
|
151
75
|
declare function getJoinMap(store: Store & {
|
|
152
76
|
joins?: Map<string, Join<any, any, any, any>>;
|
|
153
77
|
}): Map<string, Join<any, any, any, any>>;
|
|
154
|
-
declare function getJoin<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
155
|
-
type JoinStates<ASide extends string, BSide extends string, Cardinality extends
|
|
78
|
+
declare function getJoin<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, store: Store): Join<ASide, BSide, Cardinality, Content>;
|
|
79
|
+
type JoinStates<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
|
|
156
80
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntryOf${Capitalize<BSide>}` : `${AB}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
|
|
157
81
|
string,
|
|
158
82
|
Content
|
|
159
83
|
] | null>;
|
|
160
84
|
} : {}) & {
|
|
161
85
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeyOf${Capitalize<BSide>}` : `${AB}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string | null>;
|
|
162
|
-
} : Cardinality extends `1:n` ? (Content extends Json
|
|
86
|
+
} : Cardinality extends `1:n` ? (Content extends Json.Object ? {
|
|
163
87
|
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
|
|
164
88
|
string,
|
|
165
89
|
Content
|
|
@@ -173,7 +97,7 @@ type JoinStates<ASide extends string, BSide extends string, Cardinality extends
|
|
|
173
97
|
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<string | null>;
|
|
174
98
|
} & {
|
|
175
99
|
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string[]>;
|
|
176
|
-
} : Cardinality extends `n:n` ? (Content extends Json
|
|
100
|
+
} : Cardinality extends `n:n` ? (Content extends Json.Object ? {
|
|
177
101
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntriesOf${Capitalize<BSide>}` : `${AB}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
|
|
178
102
|
string,
|
|
179
103
|
Content
|
|
@@ -181,12 +105,12 @@ type JoinStates<ASide extends string, BSide extends string, Cardinality extends
|
|
|
181
105
|
} : {}) & {
|
|
182
106
|
readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeysOf${Capitalize<BSide>}` : `${AB}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string[]>;
|
|
183
107
|
} : never;
|
|
184
|
-
declare function findRelationsInStore<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
185
|
-
declare function findRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
186
|
-
declare function editRelationsInStore<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
187
|
-
declare function editRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
108
|
+
declare function findRelationsInStore<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, key: string, store: Store): JoinStates<ASide, BSide, Cardinality, Content>;
|
|
109
|
+
declare function findRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, key: string): JoinStates<ASide, BSide, Cardinality, Content>;
|
|
110
|
+
declare function editRelationsInStore<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, change: (relations: Junction<ASide, BSide, Content>) => void, store: Store): void;
|
|
111
|
+
declare function editRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, change: (relations: Junction<ASide, BSide, Content>) => void): void;
|
|
188
112
|
declare function getInternalRelationsFromStore(token: JoinToken<any, any, any, any>, store: Store): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
|
|
189
|
-
declare function getInternalRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json
|
|
113
|
+
declare function getInternalRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
|
|
190
114
|
|
|
191
115
|
declare function struct<Struct extends {
|
|
192
116
|
[key: string]: unknown;
|
package/data/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Junction } from '../../dist/chunk-IZXKJOQQ.js';
|
|
2
1
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
3
|
-
import { createStandaloneSelector, findInStore, IMPLICIT, withdraw, growMoleculeInStore, NotFoundError, initFamilyMemberInStore, getFromStore, setIntoStore, seekInStore, getJsonToken, disposeFromStore, createMutableAtomFamily, createRegularAtomFamily, createMoleculeFamily, newest, makeMoleculeInStore, isChildStore, createRegularAtom, createSelectorFamily, createReadonlySelectorFamily, getJsonFamily } from 'atom.io/internal';
|
|
2
|
+
import { createStandaloneSelector, findInStore, IMPLICIT, withdraw, growMoleculeInStore, NotFoundError, initFamilyMemberInStore, getFromStore, setIntoStore, seekInStore, getJsonToken, disposeFromStore, createMutableAtomFamily, createRegularAtomFamily, createMoleculeFamily, Junction, newest, makeMoleculeInStore, isChildStore, createRegularAtom, createSelectorFamily, createReadonlySelectorFamily, getJsonFamily } from 'atom.io/internal';
|
|
4
3
|
import { stringifyJson } from 'atom.io/json';
|
|
5
4
|
import { SetRTX } from 'atom.io/transceivers/set-rtx';
|
|
6
5
|
|
package/data/src/join.ts
CHANGED
|
@@ -16,14 +16,21 @@ import type {
|
|
|
16
16
|
} from "atom.io"
|
|
17
17
|
import type { findState } from "atom.io/ephemeral"
|
|
18
18
|
import type { seekState } from "atom.io/immortal"
|
|
19
|
-
import type {
|
|
19
|
+
import type {
|
|
20
|
+
BaseExternalStoreConfiguration,
|
|
21
|
+
ExternalStoreConfiguration,
|
|
22
|
+
JunctionEntries,
|
|
23
|
+
JunctionSchema,
|
|
24
|
+
Molecule,
|
|
25
|
+
// RelationCardinality,
|
|
26
|
+
Store,
|
|
27
|
+
} from "atom.io/internal"
|
|
20
28
|
import {
|
|
21
29
|
createMoleculeFamily,
|
|
22
30
|
createMutableAtomFamily,
|
|
23
31
|
createReadonlySelectorFamily,
|
|
24
32
|
createRegularAtomFamily,
|
|
25
33
|
disposeFromStore,
|
|
26
|
-
findInStore,
|
|
27
34
|
getFromStore,
|
|
28
35
|
getJsonFamily,
|
|
29
36
|
getJsonToken,
|
|
@@ -31,6 +38,7 @@ import {
|
|
|
31
38
|
IMPLICIT,
|
|
32
39
|
initFamilyMemberInStore,
|
|
33
40
|
isChildStore,
|
|
41
|
+
Junction,
|
|
34
42
|
makeMoleculeInStore,
|
|
35
43
|
newest,
|
|
36
44
|
NotFoundError,
|
|
@@ -42,15 +50,6 @@ import { type Json, stringifyJson } from "atom.io/json"
|
|
|
42
50
|
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
43
51
|
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
44
52
|
|
|
45
|
-
import type {
|
|
46
|
-
BaseExternalStoreConfiguration,
|
|
47
|
-
ExternalStoreConfiguration,
|
|
48
|
-
JunctionEntries,
|
|
49
|
-
JunctionSchema,
|
|
50
|
-
} from "~/packages/rel8/junction/src"
|
|
51
|
-
import { Junction } from "~/packages/rel8/junction/src"
|
|
52
|
-
import type * as Rel8 from "~/packages/rel8/types/src"
|
|
53
|
-
|
|
54
53
|
function capitalize<S extends string>(string: S): Capitalize<S> {
|
|
55
54
|
return (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>
|
|
56
55
|
}
|
|
@@ -58,7 +57,7 @@ function capitalize<S extends string>(string: S): Capitalize<S> {
|
|
|
58
57
|
export interface JoinOptions<
|
|
59
58
|
ASide extends string,
|
|
60
59
|
BSide extends string,
|
|
61
|
-
Cardinality extends
|
|
60
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
62
61
|
Content extends Json.Object | null,
|
|
63
62
|
> extends Json.Object,
|
|
64
63
|
JunctionSchema<ASide, BSide>,
|
|
@@ -70,7 +69,7 @@ export interface JoinOptions<
|
|
|
70
69
|
export type JoinStateFamilies<
|
|
71
70
|
ASide extends string,
|
|
72
71
|
BSide extends string,
|
|
73
|
-
Cardinality extends
|
|
72
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
74
73
|
Content extends Json.Object | null,
|
|
75
74
|
> = Cardinality extends `1:1`
|
|
76
75
|
? (Content extends Json.Object
|
|
@@ -742,7 +741,7 @@ export function getJoin<
|
|
|
742
741
|
export type JoinStates<
|
|
743
742
|
ASide extends string,
|
|
744
743
|
BSide extends string,
|
|
745
|
-
Cardinality extends
|
|
744
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
746
745
|
Content extends Json.Object | null,
|
|
747
746
|
> = Cardinality extends `1:1`
|
|
748
747
|
? (Content extends Json.Object
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Junction } from './chunk-IZXKJOQQ.js';
|
|
2
1
|
import { stringifyJson, parseJson, selectJson, selectJsonFamily } from 'atom.io/json';
|
|
3
2
|
import { AtomIOLogger } from 'atom.io';
|
|
4
3
|
import { getJoin, findRelations } from 'atom.io/data';
|
|
@@ -114,6 +113,265 @@ function deposit(state) {
|
|
|
114
113
|
return token;
|
|
115
114
|
}
|
|
116
115
|
|
|
116
|
+
// internal/src/junction.ts
|
|
117
|
+
var Junction = class {
|
|
118
|
+
a;
|
|
119
|
+
b;
|
|
120
|
+
cardinality;
|
|
121
|
+
relations = /* @__PURE__ */ new Map();
|
|
122
|
+
contents = /* @__PURE__ */ new Map();
|
|
123
|
+
isContent;
|
|
124
|
+
makeContentKey = (a, b) => `${a}:${b}`;
|
|
125
|
+
warn;
|
|
126
|
+
getRelatedKeys(key) {
|
|
127
|
+
return this.relations.get(key);
|
|
128
|
+
}
|
|
129
|
+
addRelation(a, b) {
|
|
130
|
+
let aRelations = this.relations.get(a);
|
|
131
|
+
let bRelations = this.relations.get(b);
|
|
132
|
+
if (aRelations) {
|
|
133
|
+
aRelations.add(b);
|
|
134
|
+
} else {
|
|
135
|
+
aRelations = /* @__PURE__ */ new Set([b]);
|
|
136
|
+
this.relations.set(a, aRelations);
|
|
137
|
+
}
|
|
138
|
+
if (bRelations) {
|
|
139
|
+
bRelations.add(a);
|
|
140
|
+
} else {
|
|
141
|
+
bRelations = /* @__PURE__ */ new Set([a]);
|
|
142
|
+
this.relations.set(b, bRelations);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
deleteRelation(a, b) {
|
|
146
|
+
const aRelations = this.relations.get(a);
|
|
147
|
+
if (aRelations) {
|
|
148
|
+
aRelations.delete(b);
|
|
149
|
+
if (aRelations.size === 0) {
|
|
150
|
+
this.relations.delete(a);
|
|
151
|
+
}
|
|
152
|
+
const bRelations = this.relations.get(b);
|
|
153
|
+
if (bRelations) {
|
|
154
|
+
bRelations.delete(a);
|
|
155
|
+
if (bRelations.size === 0) {
|
|
156
|
+
this.relations.delete(b);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
replaceRelationsUnsafely(a, bs) {
|
|
162
|
+
this.relations.set(a, new Set(bs));
|
|
163
|
+
for (const b of bs) {
|
|
164
|
+
const bRelations = /* @__PURE__ */ new Set([a]);
|
|
165
|
+
this.relations.set(b, bRelations);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
replaceRelationsSafely(a, bs) {
|
|
169
|
+
const aRelationsPrev = this.relations.get(a);
|
|
170
|
+
if (aRelationsPrev) {
|
|
171
|
+
for (const b of aRelationsPrev) {
|
|
172
|
+
const bRelations = this.relations.get(b);
|
|
173
|
+
if (bRelations) {
|
|
174
|
+
if (bRelations.size === 1) {
|
|
175
|
+
this.relations.delete(b);
|
|
176
|
+
} else {
|
|
177
|
+
bRelations.delete(a);
|
|
178
|
+
}
|
|
179
|
+
this.contents.delete(this.makeContentKey(a, b));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
this.relations.set(a, new Set(bs));
|
|
184
|
+
for (const b of bs) {
|
|
185
|
+
let bRelations = this.relations.get(b);
|
|
186
|
+
if (bRelations) {
|
|
187
|
+
bRelations.add(a);
|
|
188
|
+
} else {
|
|
189
|
+
bRelations = /* @__PURE__ */ new Set([a]);
|
|
190
|
+
this.relations.set(b, bRelations);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
getContentInternal(contentKey) {
|
|
195
|
+
return this.contents.get(contentKey);
|
|
196
|
+
}
|
|
197
|
+
setContent(contentKey, content) {
|
|
198
|
+
this.contents.set(contentKey, content);
|
|
199
|
+
}
|
|
200
|
+
deleteContent(contentKey) {
|
|
201
|
+
this.contents.delete(contentKey);
|
|
202
|
+
}
|
|
203
|
+
constructor(data, config) {
|
|
204
|
+
this.a = data.between[0];
|
|
205
|
+
this.b = data.between[1];
|
|
206
|
+
this.cardinality = data.cardinality;
|
|
207
|
+
if (!config?.externalStore) {
|
|
208
|
+
this.relations = new Map(data.relations?.map(([a, b]) => [a, new Set(b)]));
|
|
209
|
+
this.contents = new Map(data.contents);
|
|
210
|
+
}
|
|
211
|
+
this.isContent = config?.isContent ?? null;
|
|
212
|
+
if (config?.makeContentKey) {
|
|
213
|
+
this.makeContentKey = config.makeContentKey;
|
|
214
|
+
}
|
|
215
|
+
if (config?.externalStore) {
|
|
216
|
+
const externalStore = config.externalStore;
|
|
217
|
+
this.has = (a, b) => externalStore.has(a, b);
|
|
218
|
+
this.addRelation = (a, b) => {
|
|
219
|
+
externalStore.addRelation(a, b);
|
|
220
|
+
};
|
|
221
|
+
this.deleteRelation = (a, b) => {
|
|
222
|
+
externalStore.deleteRelation(a, b);
|
|
223
|
+
};
|
|
224
|
+
this.replaceRelationsSafely = (a, bs) => {
|
|
225
|
+
externalStore.replaceRelationsSafely(a, bs);
|
|
226
|
+
};
|
|
227
|
+
this.replaceRelationsUnsafely = (a, bs) => {
|
|
228
|
+
externalStore.replaceRelationsUnsafely(a, bs);
|
|
229
|
+
};
|
|
230
|
+
this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
|
|
231
|
+
if (externalStore.getContent) {
|
|
232
|
+
this.getContentInternal = (contentKey) => {
|
|
233
|
+
return externalStore.getContent(contentKey);
|
|
234
|
+
};
|
|
235
|
+
this.setContent = (contentKey, content) => {
|
|
236
|
+
externalStore.setContent(contentKey, content);
|
|
237
|
+
};
|
|
238
|
+
this.deleteContent = (contentKey) => {
|
|
239
|
+
externalStore.deleteContent(contentKey);
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
for (const [x, ys] of data.relations ?? []) {
|
|
243
|
+
for (const y of ys) this.addRelation(x, y);
|
|
244
|
+
}
|
|
245
|
+
for (const [contentKey, content] of data.contents ?? []) {
|
|
246
|
+
this.setContent(contentKey, content);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (config?.warn) {
|
|
250
|
+
this.warn = config.warn;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
toJSON() {
|
|
254
|
+
return {
|
|
255
|
+
between: [this.a, this.b],
|
|
256
|
+
cardinality: this.cardinality,
|
|
257
|
+
relations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),
|
|
258
|
+
contents: [...this.contents.entries()]
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
set(a, ...rest) {
|
|
262
|
+
const b = typeof rest[0] === `string` ? rest[0] : a[this.b];
|
|
263
|
+
const content = rest[1] ?? typeof rest[0] === `string` ? void 0 : rest[0];
|
|
264
|
+
a = typeof a === `string` ? a : a[this.a];
|
|
265
|
+
switch (this.cardinality) {
|
|
266
|
+
// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here
|
|
267
|
+
case `1:1`: {
|
|
268
|
+
const bPrev = this.getRelatedKey(a);
|
|
269
|
+
if (bPrev && bPrev !== b) this.delete(bPrev, a);
|
|
270
|
+
}
|
|
271
|
+
case `1:n`: {
|
|
272
|
+
const aPrev = this.getRelatedKey(b);
|
|
273
|
+
if (aPrev && aPrev !== a) this.delete(aPrev, b);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (content) {
|
|
277
|
+
const contentKey = this.makeContentKey(a, b);
|
|
278
|
+
this.setContent(contentKey, content);
|
|
279
|
+
}
|
|
280
|
+
this.addRelation(a, b);
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
delete(x, b) {
|
|
284
|
+
b = typeof b === `string` ? b : x[this.b];
|
|
285
|
+
const a = typeof x === `string` ? x : x[this.a];
|
|
286
|
+
if (a === void 0 && typeof b === `string`) {
|
|
287
|
+
const bRelations = this.getRelatedKeys(b);
|
|
288
|
+
if (bRelations) {
|
|
289
|
+
for (const bRelation of bRelations) {
|
|
290
|
+
this.delete(bRelation, b);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (typeof a === `string` && b === void 0) {
|
|
295
|
+
const aRelations = this.getRelatedKeys(a);
|
|
296
|
+
if (aRelations) {
|
|
297
|
+
for (const aRelation of aRelations) {
|
|
298
|
+
this.delete(a, aRelation);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (typeof a === `string` && typeof b === `string`) {
|
|
303
|
+
this.deleteRelation(a, b);
|
|
304
|
+
const contentKey = this.makeContentKey(a, b);
|
|
305
|
+
this.deleteContent(contentKey);
|
|
306
|
+
}
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
getRelatedKey(key) {
|
|
310
|
+
const relations = this.getRelatedKeys(key);
|
|
311
|
+
if (relations) {
|
|
312
|
+
if (relations.size > 1) {
|
|
313
|
+
this.warn?.(
|
|
314
|
+
`${relations.size} related keys were found for key "${key}": (${[
|
|
315
|
+
...relations
|
|
316
|
+
].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
for (const relation of relations) {
|
|
320
|
+
return relation;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
replaceRelations(a, relations, config) {
|
|
325
|
+
const hasContent = !Array.isArray(relations);
|
|
326
|
+
const bs = hasContent ? Object.keys(relations) : relations;
|
|
327
|
+
if (config?.reckless) {
|
|
328
|
+
this.replaceRelationsUnsafely(a, bs);
|
|
329
|
+
} else {
|
|
330
|
+
this.replaceRelationsSafely(a, bs);
|
|
331
|
+
}
|
|
332
|
+
if (hasContent) {
|
|
333
|
+
for (const b of bs) {
|
|
334
|
+
const contentKey = this.makeContentKey(a, b);
|
|
335
|
+
const content = relations[b];
|
|
336
|
+
this.setContent(contentKey, content);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return this;
|
|
340
|
+
}
|
|
341
|
+
getContent(a, b) {
|
|
342
|
+
const contentKey = this.makeContentKey(a, b);
|
|
343
|
+
return this.getContentInternal(contentKey);
|
|
344
|
+
}
|
|
345
|
+
getRelationEntries(input) {
|
|
346
|
+
const a = input[this.a];
|
|
347
|
+
const b = input[this.b];
|
|
348
|
+
if (a !== void 0 && b === void 0) {
|
|
349
|
+
const aRelations = this.getRelatedKeys(a);
|
|
350
|
+
if (aRelations) {
|
|
351
|
+
return [...aRelations].map((aRelation) => {
|
|
352
|
+
return [aRelation, this.getContent(a, aRelation) ?? null];
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (a === void 0 && b !== void 0) {
|
|
357
|
+
const bRelations = this.getRelatedKeys(b);
|
|
358
|
+
if (bRelations) {
|
|
359
|
+
return [...bRelations].map((bRelation) => {
|
|
360
|
+
return [bRelation, this.getContent(bRelation, b) ?? null];
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
has(a, b) {
|
|
367
|
+
if (b) {
|
|
368
|
+
const setA = this.getRelatedKeys(a);
|
|
369
|
+
return setA?.has(b) ?? false;
|
|
370
|
+
}
|
|
371
|
+
return this.relations.has(a);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
117
375
|
// internal/src/subject.ts
|
|
118
376
|
var Subject = class {
|
|
119
377
|
Subscriber;
|
|
@@ -3228,4 +3486,4 @@ var timeTravel = (store, action, token) => {
|
|
|
3228
3486
|
);
|
|
3229
3487
|
};
|
|
3230
3488
|
|
|
3231
|
-
export { FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, LazyMap, Molecule, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, createWritableSelectorFamily, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, eldest, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState2 as subscribeToState, subscribeToTimeline2 as subscribeToTimeline, subscribeToTransaction2 as subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
|
3489
|
+
export { FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, Molecule, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, createWritableSelectorFamily, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, eldest, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState2 as subscribeToState, subscribeToTimeline2 as subscribeToTimeline, subscribeToTransaction2 as subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|