atom.io 0.6.9 → 0.8.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/README.md +21 -2
- package/dist/index.d.mts +34 -421
- package/dist/index.d.ts +34 -421
- package/dist/index.js +248 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -4
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +364 -0
- package/internal/dist/index.d.ts +364 -0
- package/internal/dist/index.js +1906 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +1830 -0
- package/internal/dist/index.mjs.map +1 -0
- package/internal/package.json +15 -0
- package/internal/src/atom/create-atom.ts +75 -0
- package/internal/src/atom/delete-atom.ts +10 -0
- package/internal/src/atom/index.ts +3 -0
- package/internal/src/atom/is-default.ts +37 -0
- package/internal/src/caching.ts +38 -0
- package/internal/src/families/create-atom-family.ts +59 -0
- package/internal/src/families/create-readonly-selector-family.ts +45 -0
- package/internal/src/families/create-selector-family.ts +67 -0
- package/internal/src/families/index.ts +3 -0
- package/internal/src/future.ts +39 -0
- package/internal/src/get-state-internal.ts +23 -0
- package/internal/src/index.ts +14 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
- package/internal/src/mutable/create-mutable-atom.ts +49 -0
- package/internal/src/mutable/get-json-token.ts +22 -0
- package/internal/src/mutable/get-update-token.ts +20 -0
- package/internal/src/mutable/index.ts +17 -0
- package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
- package/internal/src/mutable/tracker-family.ts +61 -0
- package/internal/src/mutable/tracker.ts +164 -0
- package/internal/src/mutable/transceiver.ts +110 -0
- package/internal/src/operation.ts +68 -0
- package/internal/src/selector/create-read-write-selector.ts +65 -0
- package/internal/src/selector/create-readonly-selector.ts +49 -0
- package/internal/src/selector/create-selector.ts +65 -0
- package/internal/src/selector/index.ts +5 -0
- package/internal/src/selector/lookup-selector-sources.ts +20 -0
- package/internal/src/selector/register-selector.ts +61 -0
- package/internal/src/selector/trace-selector-atoms.ts +45 -0
- package/internal/src/selector/update-selector-atoms.ts +34 -0
- package/internal/src/set-state/become.ts +10 -0
- package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
- package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
- package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
- package/internal/src/set-state/emit-update.ts +23 -0
- package/internal/src/set-state/evict-downstream.ts +39 -0
- package/internal/src/set-state/index.ts +2 -0
- package/internal/src/set-state/set-atom-state.ts +38 -0
- package/internal/src/set-state/set-selector-state.ts +19 -0
- package/internal/src/set-state/set-state-internal.ts +18 -0
- package/internal/src/set-state/stow-update.ts +42 -0
- package/internal/src/store/deposit.ts +43 -0
- package/internal/src/store/index.ts +5 -0
- package/internal/src/store/lookup.ts +26 -0
- package/internal/src/store/store.ts +154 -0
- package/internal/src/store/withdraw-new-family-member.ts +53 -0
- package/internal/src/store/withdraw.ts +113 -0
- package/internal/src/subject.ts +21 -0
- package/internal/src/subscribe/index.ts +1 -0
- package/internal/src/subscribe/recall-state.ts +19 -0
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
- package/internal/src/timeline/add-atom-to-timeline.ts +189 -0
- package/internal/src/timeline/index.ts +3 -0
- package/internal/src/timeline/time-travel-internal.ts +91 -0
- package/internal/src/timeline/timeline-internal.ts +115 -0
- package/internal/src/transaction/abort-transaction.ts +12 -0
- package/internal/src/transaction/apply-transaction.ts +64 -0
- package/internal/src/transaction/build-transaction.ts +39 -0
- package/internal/src/transaction/index.ts +26 -0
- package/internal/src/transaction/redo-transaction.ts +22 -0
- package/internal/src/transaction/transaction-internal.ts +64 -0
- package/internal/src/transaction/undo-transaction.ts +22 -0
- package/introspection/dist/index.d.mts +3 -197
- package/introspection/dist/index.d.ts +3 -197
- package/introspection/dist/index.js +329 -4
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +310 -4
- package/introspection/dist/index.mjs.map +1 -1
- package/introspection/src/attach-atom-index.ts +84 -0
- package/introspection/src/attach-introspection-states.ts +38 -0
- package/introspection/src/attach-selector-index.ts +90 -0
- package/introspection/src/attach-timeline-family.ts +59 -0
- package/introspection/src/attach-timeline-index.ts +38 -0
- package/introspection/src/attach-transaction-index.ts +40 -0
- package/introspection/src/attach-transaction-logs.ts +43 -0
- package/introspection/src/index.ts +20 -0
- package/json/dist/index.d.mts +10 -2
- package/json/dist/index.d.ts +10 -2
- package/json/dist/index.js +83 -26
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +74 -3
- package/json/dist/index.mjs.map +1 -1
- package/json/src/index.ts +5 -0
- package/json/src/select-json-family.ts +35 -0
- package/json/src/select-json.ts +22 -0
- package/package.json +103 -63
- package/react/dist/index.d.mts +9 -17
- package/react/dist/index.d.ts +9 -17
- package/react/dist/index.js +44 -27
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +24 -4
- package/react/dist/index.mjs.map +1 -1
- package/react/src/index.ts +2 -0
- package/react/src/store-context.tsx +12 -0
- package/react/src/store-hooks.ts +36 -0
- package/react-devtools/dist/index.css +50 -1
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +104 -71
- package/react-devtools/dist/index.d.ts +104 -71
- package/react-devtools/dist/index.js +2821 -45
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +2790 -11
- package/react-devtools/dist/index.mjs.map +1 -1
- package/react-devtools/src/AtomIODevtools.tsx +109 -0
- package/react-devtools/src/Button.tsx +23 -0
- package/react-devtools/src/StateEditor.tsx +75 -0
- package/react-devtools/src/StateIndex.tsx +159 -0
- package/react-devtools/src/TimelineIndex.tsx +88 -0
- package/react-devtools/src/TransactionIndex.tsx +70 -0
- package/react-devtools/src/Updates.tsx +150 -0
- package/react-devtools/src/devtools.scss +310 -0
- package/react-devtools/src/index.ts +72 -0
- package/realtime-react/dist/index.d.mts +8 -22
- package/realtime-react/dist/index.d.ts +8 -22
- package/realtime-react/dist/index.js +87 -32
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +62 -6
- package/realtime-react/dist/index.mjs.map +1 -1
- package/realtime-react/src/index.ts +7 -0
- package/realtime-react/src/realtime-context.tsx +29 -0
- package/realtime-react/src/use-pull-family-member.ts +15 -0
- package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
- package/realtime-react/src/use-pull-mutable.ts +17 -0
- package/realtime-react/src/use-pull.ts +15 -0
- package/realtime-react/src/use-push.ts +19 -0
- package/realtime-react/src/use-server-action.ts +18 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +147 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +116 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/realtime-testing/src/index.ts +1 -0
- package/realtime-testing/src/setup-realtime-test.tsx +161 -0
- package/src/atom.ts +64 -9
- package/src/index.ts +29 -31
- package/src/logger.ts +3 -3
- package/src/selector.ts +3 -3
- package/src/silo.ts +29 -20
- package/src/subscribe.ts +3 -3
- package/src/timeline.ts +2 -2
- package/transceivers/set-rtx/dist/index.d.mts +39 -0
- package/transceivers/set-rtx/dist/index.d.ts +39 -0
- package/transceivers/set-rtx/dist/index.js +213 -0
- package/transceivers/set-rtx/dist/index.js.map +1 -0
- package/transceivers/set-rtx/dist/index.mjs +211 -0
- package/transceivers/set-rtx/dist/index.mjs.map +1 -0
- package/{realtime → transceivers/set-rtx}/package.json +1 -1
- package/transceivers/set-rtx/src/index.ts +1 -0
- package/transceivers/set-rtx/src/set-rtx.ts +242 -0
- package/realtime/dist/index.d.mts +0 -23
- package/realtime/dist/index.d.ts +0 -23
- package/realtime/dist/index.js +0 -32
- package/realtime/dist/index.js.map +0 -1
- package/realtime/dist/index.mjs +0 -7
- package/realtime/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ReadonlySelectorFamily } from "atom.io"
|
|
2
|
+
import type { Store, Timeline } from "atom.io/internal"
|
|
3
|
+
import {
|
|
4
|
+
IMPLICIT,
|
|
5
|
+
Subject,
|
|
6
|
+
createAtomFamily,
|
|
7
|
+
createSelectorFamily,
|
|
8
|
+
} from "atom.io/internal"
|
|
9
|
+
|
|
10
|
+
export const attachTimelineFamily = (
|
|
11
|
+
store: Store = IMPLICIT.STORE,
|
|
12
|
+
): ReadonlySelectorFamily<Timeline> => {
|
|
13
|
+
const findTimelineLogState__INTERNAL = createAtomFamily<Timeline, string>(
|
|
14
|
+
{
|
|
15
|
+
key: `👁🗨 Timeline Update Log (Internal)`,
|
|
16
|
+
default: (key) =>
|
|
17
|
+
store.timelines.get(key) ?? {
|
|
18
|
+
type: `timeline`,
|
|
19
|
+
key: ``,
|
|
20
|
+
at: 0,
|
|
21
|
+
timeTraveling: null,
|
|
22
|
+
history: [],
|
|
23
|
+
selectorTime: null,
|
|
24
|
+
transactionKey: null,
|
|
25
|
+
install: () => {},
|
|
26
|
+
subject: new Subject(),
|
|
27
|
+
},
|
|
28
|
+
effects: (key) => [
|
|
29
|
+
({ setSelf }) => {
|
|
30
|
+
const tl = store.timelines.get(key)
|
|
31
|
+
tl?.subject.subscribe(`introspection`, (_) => {
|
|
32
|
+
if (store.operation.open === true) {
|
|
33
|
+
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
34
|
+
`introspection`,
|
|
35
|
+
(operationStatus) => {
|
|
36
|
+
if (operationStatus.open === false) {
|
|
37
|
+
unsubscribe()
|
|
38
|
+
setSelf({ ...tl })
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
)
|
|
42
|
+
} else {
|
|
43
|
+
setSelf({ ...tl })
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
store,
|
|
50
|
+
)
|
|
51
|
+
const findTimelineLogState = createSelectorFamily<Timeline, string>(
|
|
52
|
+
{
|
|
53
|
+
key: `👁🗨 Timeline Update Log`,
|
|
54
|
+
get: (key) => ({ get }) => get(findTimelineLogState__INTERNAL(key)),
|
|
55
|
+
},
|
|
56
|
+
store,
|
|
57
|
+
)
|
|
58
|
+
return findTimelineLogState
|
|
59
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ReadonlySelectorToken, TimelineToken } from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { IMPLICIT, createAtom, createSelector } from "atom.io/internal"
|
|
4
|
+
|
|
5
|
+
export const attachTimelineIndex = (
|
|
6
|
+
store: Store = IMPLICIT.STORE,
|
|
7
|
+
): ReadonlySelectorToken<TimelineToken[]> => {
|
|
8
|
+
const timelineTokenIndexState__INTERNAL = createAtom<TimelineToken[]>(
|
|
9
|
+
{
|
|
10
|
+
key: `👁🗨 Timeline Token Index (Internal)`,
|
|
11
|
+
default: () =>
|
|
12
|
+
[...store.timelines].map(([key]): TimelineToken => {
|
|
13
|
+
return { key, type: `timeline` }
|
|
14
|
+
}),
|
|
15
|
+
effects: [
|
|
16
|
+
({ setSelf }) => {
|
|
17
|
+
store.subject.timelineCreation.subscribe(
|
|
18
|
+
`introspection`,
|
|
19
|
+
(timelineToken) => {
|
|
20
|
+
setSelf((state) => [...state, timelineToken])
|
|
21
|
+
},
|
|
22
|
+
)
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
undefined,
|
|
27
|
+
store,
|
|
28
|
+
)
|
|
29
|
+
const timelineTokenIndex = createSelector(
|
|
30
|
+
{
|
|
31
|
+
key: `👁🗨 Timeline Token Index`,
|
|
32
|
+
get: ({ get }) => get(timelineTokenIndexState__INTERNAL),
|
|
33
|
+
},
|
|
34
|
+
undefined,
|
|
35
|
+
store,
|
|
36
|
+
)
|
|
37
|
+
return timelineTokenIndex
|
|
38
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReadonlySelectorToken, TransactionToken, ƒn } from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { IMPLICIT, createAtom, createSelector } from "atom.io/internal"
|
|
4
|
+
|
|
5
|
+
export const attachTransactionIndex = (
|
|
6
|
+
store: Store = IMPLICIT.STORE,
|
|
7
|
+
): ReadonlySelectorToken<TransactionToken<ƒn>[]> => {
|
|
8
|
+
const transactionTokenIndexState__INTERNAL = createAtom<
|
|
9
|
+
TransactionToken<ƒn>[]
|
|
10
|
+
>(
|
|
11
|
+
{
|
|
12
|
+
key: `👁🗨 Transaction Token Index (Internal)`,
|
|
13
|
+
default: () =>
|
|
14
|
+
[...store.transactions].map(([key]): TransactionToken<ƒn> => {
|
|
15
|
+
return { key, type: `transaction` }
|
|
16
|
+
}),
|
|
17
|
+
effects: [
|
|
18
|
+
({ setSelf }) => {
|
|
19
|
+
store.subject.transactionCreation.subscribe(
|
|
20
|
+
`introspection`,
|
|
21
|
+
(transactionToken) => {
|
|
22
|
+
setSelf((state) => [...state, transactionToken])
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
undefined,
|
|
29
|
+
store,
|
|
30
|
+
)
|
|
31
|
+
const transactionTokenIndex = createSelector(
|
|
32
|
+
{
|
|
33
|
+
key: `👁🗨 Transaction Token Index`,
|
|
34
|
+
get: ({ get }) => get(transactionTokenIndexState__INTERNAL),
|
|
35
|
+
},
|
|
36
|
+
undefined,
|
|
37
|
+
store,
|
|
38
|
+
)
|
|
39
|
+
return transactionTokenIndex
|
|
40
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReadonlySelectorFamily, TransactionUpdate, ƒn } from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import {
|
|
4
|
+
IMPLICIT,
|
|
5
|
+
createAtomFamily,
|
|
6
|
+
createSelectorFamily,
|
|
7
|
+
} from "atom.io/internal"
|
|
8
|
+
|
|
9
|
+
export const attachTransactionLogs = (
|
|
10
|
+
store: Store = IMPLICIT.STORE,
|
|
11
|
+
): ReadonlySelectorFamily<TransactionUpdate<ƒn>[]> => {
|
|
12
|
+
const findTransactionUpdateLog = createAtomFamily<
|
|
13
|
+
TransactionUpdate<ƒn>[],
|
|
14
|
+
string
|
|
15
|
+
>(
|
|
16
|
+
{
|
|
17
|
+
key: `👁🗨 Transaction Update Log (Internal)`,
|
|
18
|
+
default: () => [],
|
|
19
|
+
effects: (key) => [
|
|
20
|
+
({ setSelf }) => {
|
|
21
|
+
const tx = store.transactions.get(key)
|
|
22
|
+
tx?.subject.subscribe(`introspection`, (transactionUpdate) => {
|
|
23
|
+
if (transactionUpdate.key === key) {
|
|
24
|
+
setSelf((state) => [...state, transactionUpdate])
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
store,
|
|
31
|
+
)
|
|
32
|
+
const findTransactionUpdateLogState = createSelectorFamily<
|
|
33
|
+
TransactionUpdate<ƒn>[],
|
|
34
|
+
string
|
|
35
|
+
>(
|
|
36
|
+
{
|
|
37
|
+
key: `👁🗨 Transaction Update Log`,
|
|
38
|
+
get: (key) => ({ get }) => get(findTransactionUpdateLog(key)),
|
|
39
|
+
},
|
|
40
|
+
store,
|
|
41
|
+
)
|
|
42
|
+
return findTransactionUpdateLogState
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AtomToken, ReadonlySelectorToken, SelectorToken } from "atom.io"
|
|
2
|
+
|
|
3
|
+
export * from "./attach-introspection-states"
|
|
4
|
+
|
|
5
|
+
export type FamilyNode<
|
|
6
|
+
Token extends
|
|
7
|
+
| AtomToken<unknown>
|
|
8
|
+
| ReadonlySelectorToken<unknown>
|
|
9
|
+
| SelectorToken<unknown>,
|
|
10
|
+
> = {
|
|
11
|
+
key: string
|
|
12
|
+
familyMembers: Record<string, Token>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type StateTokenIndex<
|
|
16
|
+
Token extends
|
|
17
|
+
| AtomToken<unknown>
|
|
18
|
+
| ReadonlySelectorToken<unknown>
|
|
19
|
+
| SelectorToken<unknown>,
|
|
20
|
+
> = Record<string, FamilyNode<Token> | Token>
|
package/json/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as AtomIO from 'atom.io';
|
|
2
|
+
import { Store } from 'atom.io/internal';
|
|
2
3
|
|
|
3
4
|
type JsonInterface<T, J extends Serializable = Serializable> = {
|
|
4
5
|
toJson: (t: T) => J;
|
|
@@ -7,6 +8,11 @@ type JsonInterface<T, J extends Serializable = Serializable> = {
|
|
|
7
8
|
declare const stringSetJsonInterface: JsonInterface<Set<string>, Array<string>>;
|
|
8
9
|
|
|
9
10
|
type primitive = boolean | number | string | null;
|
|
11
|
+
declare const isString: (input: unknown) => input is string;
|
|
12
|
+
declare const isNumber: (input: unknown) => input is number;
|
|
13
|
+
declare const isBoolean: (input: unknown) => input is boolean;
|
|
14
|
+
declare const isNull: (input: unknown) => input is null;
|
|
15
|
+
declare const isPrimitive: (input: unknown) => input is primitive;
|
|
10
16
|
|
|
11
17
|
type Serializable = primitive | Readonly<{
|
|
12
18
|
[key: string]: Serializable;
|
|
@@ -42,6 +48,8 @@ interface JsonTypes extends Record<JsonTypeName, Serializable> {
|
|
|
42
48
|
}
|
|
43
49
|
declare const JSON_DEFAULTS: JsonTypes;
|
|
44
50
|
|
|
45
|
-
declare const selectJson: <T, J extends
|
|
51
|
+
declare const selectJson: <T, J extends Serializable>(atom: AtomIO.AtomToken<T>, transform: JsonInterface<T, J>, store?: Store) => AtomIO.SelectorToken<J>;
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
declare const selectJsonFamily: <T, J extends Serializable, K extends Serializable>(atomFamily: AtomIO.AtomFamily<T, K>, transform: JsonInterface<T, J>, store?: Store) => AtomIO.SelectorFamily<J, K>;
|
|
54
|
+
|
|
55
|
+
export { Empty, JSON_DEFAULTS, JSON_TYPE_NAMES, json as Json, JsonInterface, JsonTypeName, JsonTypes, Stringified, isBoolean, isNull, isNumber, isPrimitive, isString, parseJson, primitive, selectJson, selectJsonFamily, stringSetJsonInterface, stringifyJson };
|
package/json/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as AtomIO from 'atom.io';
|
|
2
|
+
import { Store } from 'atom.io/internal';
|
|
2
3
|
|
|
3
4
|
type JsonInterface<T, J extends Serializable = Serializable> = {
|
|
4
5
|
toJson: (t: T) => J;
|
|
@@ -7,6 +8,11 @@ type JsonInterface<T, J extends Serializable = Serializable> = {
|
|
|
7
8
|
declare const stringSetJsonInterface: JsonInterface<Set<string>, Array<string>>;
|
|
8
9
|
|
|
9
10
|
type primitive = boolean | number | string | null;
|
|
11
|
+
declare const isString: (input: unknown) => input is string;
|
|
12
|
+
declare const isNumber: (input: unknown) => input is number;
|
|
13
|
+
declare const isBoolean: (input: unknown) => input is boolean;
|
|
14
|
+
declare const isNull: (input: unknown) => input is null;
|
|
15
|
+
declare const isPrimitive: (input: unknown) => input is primitive;
|
|
10
16
|
|
|
11
17
|
type Serializable = primitive | Readonly<{
|
|
12
18
|
[key: string]: Serializable;
|
|
@@ -42,6 +48,8 @@ interface JsonTypes extends Record<JsonTypeName, Serializable> {
|
|
|
42
48
|
}
|
|
43
49
|
declare const JSON_DEFAULTS: JsonTypes;
|
|
44
50
|
|
|
45
|
-
declare const selectJson: <T, J extends
|
|
51
|
+
declare const selectJson: <T, J extends Serializable>(atom: AtomIO.AtomToken<T>, transform: JsonInterface<T, J>, store?: Store) => AtomIO.SelectorToken<J>;
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
declare const selectJsonFamily: <T, J extends Serializable, K extends Serializable>(atomFamily: AtomIO.AtomFamily<T, K>, transform: JsonInterface<T, J>, store?: Store) => AtomIO.SelectorFamily<J, K>;
|
|
54
|
+
|
|
55
|
+
export { Empty, JSON_DEFAULTS, JSON_TYPE_NAMES, json as Json, JsonInterface, JsonTypeName, JsonTypes, Stringified, isBoolean, isNull, isNumber, isPrimitive, isString, parseJson, primitive, selectJson, selectJsonFamily, stringSetJsonInterface, stringifyJson };
|
package/json/dist/index.js
CHANGED
|
@@ -1,34 +1,91 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var internal = require('atom.io/internal');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
5
|
+
// ../../anvl/src/json/json-interface.ts
|
|
6
|
+
var stringSetJsonInterface = {
|
|
7
|
+
toJson: (stringSet) => Array.from(stringSet),
|
|
8
|
+
fromJson: (json) => new Set(json)
|
|
9
|
+
};
|
|
22
10
|
|
|
23
|
-
|
|
11
|
+
// ../../anvl/src/json/index.ts
|
|
12
|
+
var parseJson = (str) => JSON.parse(str);
|
|
13
|
+
var stringifyJson = (json) => JSON.stringify(json);
|
|
14
|
+
var JSON_TYPE_NAMES = [
|
|
15
|
+
`array`,
|
|
16
|
+
`boolean`,
|
|
17
|
+
`null`,
|
|
18
|
+
`number`,
|
|
19
|
+
`object`,
|
|
20
|
+
`string`
|
|
21
|
+
];
|
|
22
|
+
var JSON_DEFAULTS = {
|
|
23
|
+
array: [],
|
|
24
|
+
boolean: false,
|
|
25
|
+
null: null,
|
|
26
|
+
number: 0,
|
|
27
|
+
object: {},
|
|
28
|
+
string: ``
|
|
29
|
+
};
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
// ../../anvl/src/primitive/index.ts
|
|
32
|
+
var isString = (input) => {
|
|
33
|
+
return typeof input === `string`;
|
|
34
|
+
};
|
|
35
|
+
var isNumber = (input) => {
|
|
36
|
+
return typeof input === `number`;
|
|
37
|
+
};
|
|
38
|
+
var isBoolean = (input) => {
|
|
39
|
+
return typeof input === `boolean`;
|
|
40
|
+
};
|
|
41
|
+
var isNull = (input) => {
|
|
42
|
+
return input === null;
|
|
43
|
+
};
|
|
44
|
+
var isPrimitive = (input) => {
|
|
45
|
+
return isString(input) || isNumber(input) || isBoolean(input) || isNull(input);
|
|
46
|
+
};
|
|
47
|
+
var selectJson = (atom, transform, store = internal.IMPLICIT.STORE) => {
|
|
48
|
+
return internal.createSelector(
|
|
49
|
+
{
|
|
50
|
+
key: `${atom.key}:JSON`,
|
|
51
|
+
get: ({ get }) => transform.toJson(get(atom)),
|
|
52
|
+
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
|
|
53
|
+
},
|
|
54
|
+
void 0,
|
|
55
|
+
store
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
var selectJsonFamily = (atomFamily, transform, store = internal.IMPLICIT.STORE) => {
|
|
59
|
+
const jsonFamily = internal.createSelectorFamily(
|
|
60
|
+
{
|
|
61
|
+
key: `${atomFamily.key}:JSON`,
|
|
62
|
+
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
63
|
+
set: (key) => ({ set }, newValue) => set(atomFamily(key), transform.fromJson(newValue))
|
|
64
|
+
},
|
|
65
|
+
store
|
|
66
|
+
);
|
|
67
|
+
atomFamily.subject.subscribe(
|
|
68
|
+
`store=${store.config.name}::json-selector-family`,
|
|
69
|
+
(token) => {
|
|
70
|
+
if (token.family) {
|
|
71
|
+
jsonFamily(parseJson(token.family.subKey));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
return jsonFamily;
|
|
76
|
+
};
|
|
26
77
|
|
|
27
|
-
exports.JSON_DEFAULTS =
|
|
28
|
-
exports.JSON_TYPE_NAMES =
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
78
|
+
exports.JSON_DEFAULTS = JSON_DEFAULTS;
|
|
79
|
+
exports.JSON_TYPE_NAMES = JSON_TYPE_NAMES;
|
|
80
|
+
exports.isBoolean = isBoolean;
|
|
81
|
+
exports.isNull = isNull;
|
|
82
|
+
exports.isNumber = isNumber;
|
|
83
|
+
exports.isPrimitive = isPrimitive;
|
|
84
|
+
exports.isString = isString;
|
|
85
|
+
exports.parseJson = parseJson;
|
|
86
|
+
exports.selectJson = selectJson;
|
|
87
|
+
exports.selectJsonFamily = selectJsonFamily;
|
|
88
|
+
exports.stringSetJsonInterface = stringSetJsonInterface;
|
|
89
|
+
exports.stringifyJson = stringifyJson;
|
|
33
90
|
//# sourceMappingURL=out.js.map
|
|
34
91
|
//# sourceMappingURL=index.js.map
|
package/json/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../anvl/src/json/json-interface.ts","../../../anvl/src/json/index.ts","../src/select-json.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../anvl/src/json/json-interface.ts","../../../anvl/src/json/index.ts","../../../anvl/src/primitive/index.ts","../src/select-json.ts","../src/select-json-family.ts"],"names":["IMPLICIT"],"mappings":";AAOO,IAAM,yBAGT;AAAA,EACH,QAAQ,CAAC,cAAc,MAAM,KAAK,SAAS;AAAA,EAC3C,UAAU,CAAC,SAAS,IAAI,IAAI,IAAI;AACjC;;;ACTO,IAAM,YAAY,CACxB,QAC4D,KAAK,MAAM,GAAG;AAIpE,IAAM,gBAAgB,CAC5B,SACoB,KAAK,UAAU,IAAI;AAIjC,IAAM,kBAAkB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAaO,IAAM,gBAA2B;AAAA,EACvC,OAAO,CAAC;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ,CAAC;AAAA,EACT,QAAQ;AACT;;;ACzCO,IAAM,WAAW,CAAC,UAAoC;AAC5D,SAAO,OAAO,UAAU;AACzB;AAEO,IAAM,WAAW,CAAC,UAAoC;AAC5D,SAAO,OAAO,UAAU;AACzB;AAEO,IAAM,YAAY,CAAC,UAAqC;AAC9D,SAAO,OAAO,UAAU;AACzB;AAEO,IAAM,SAAS,CAAC,UAAkC;AACxD,SAAO,UAAU;AAClB;AAEO,IAAM,cAAc,CAAC,UAAuC;AAClE,SAAO,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;AAC9E;;;AClBA,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAGxB,IAAM,aAAa,CACzB,MACA,WACA,QAAe,SAAS,UACK;AAC7B,SAAO;AAAA,IACN;AAAA,MACC,KAAK,GAAG,KAAK,GAAG;AAAA,MAChB,KAAK,CAAC,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,IAAI,CAAC;AAAA,MAC5C,KAAK,CAAC,EAAE,IAAI,GAAG,aAAa,IAAI,MAAM,UAAU,SAAS,QAAQ,CAAC;AAAA,IACnE;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;ACnBA,SAAS,YAAAA,WAAU,4BAA4B;AAKxC,IAAM,mBAAmB,CAK/B,YACA,WACA,QAAeA,UAAS,UACS;AACjC,QAAM,aAAa;AAAA,IAClB;AAAA,MACC,KAAK,GAAG,WAAW,GAAG;AAAA,MACtB,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,WAAW,GAAG,CAAC,CAAC;AAAA,MAChE,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,aACvB,IAAI,WAAW,GAAG,GAAG,UAAU,SAAS,QAAQ,CAAC;AAAA,IACnD;AAAA,IACA;AAAA,EACD;AACA,aAAW,QAAQ;AAAA,IAClB,SAAS,MAAM,OAAO,IAAI;AAAA,IAC1B,CAAC,UAAU;AACV,UAAI,MAAM,QAAQ;AACjB,mBAAW,UAAU,MAAM,OAAO,MAAM,CAAM;AAAA,MAC/C;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR","sourcesContent":["import type { Json } from \".\"\n\nexport type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {\n\ttoJson: (t: T) => J\n\tfromJson: (json: J) => T\n}\n\nexport const stringSetJsonInterface: JsonInterface<\n\tSet<string>,\n\tJson.Array<string>\n> = {\n\ttoJson: (stringSet) => Array.from(stringSet),\n\tfromJson: (json) => new Set(json),\n}\n","export * from \"./json-interface\"\nimport type * as Json from \"./json\"\nexport { Json }\n\nexport const parseJson = <S extends Stringified<Json.Serializable>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json.Serializable => JSON.parse(str)\n\nexport type Stringified<J extends Json.Serializable> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json.Serializable>(\n\tjson: J,\n): Stringified<J> => JSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json.Serializable> {\n\tarray: Json.Array\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: Json.Object\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\n}\n","export type primitive = boolean | number | string | null\n\nexport const isString = (input: unknown): input is string => {\n\treturn typeof input === `string`\n}\n\nexport const isNumber = (input: unknown): input is number => {\n\treturn typeof input === `number`\n}\n\nexport const isBoolean = (input: unknown): input is boolean => {\n\treturn typeof input === `boolean`\n}\n\nexport const isNull = (input: unknown): input is null => {\n\treturn input === null\n}\n\nexport const isPrimitive = (input: unknown): input is primitive => {\n\treturn isString(input) || isNumber(input) || isBoolean(input) || isNull(input)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createSelector } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \".\"\n\nexport const selectJson = <T, J extends Json.Serializable>(\n\tatom: AtomIO.AtomToken<T>,\n\ttransform: JsonInterface<T, J>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.SelectorToken<J> => {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `${atom.key}:JSON`,\n\t\t\tget: ({ get }) => transform.toJson(get(atom)),\n\t\t\tset: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelectorFamily } from \"atom.io/internal\"\n\nimport type { Json, JsonInterface } from \".\"\nimport { parseJson } from \".\"\n\nexport const selectJsonFamily = <\n\tT,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(\n\tatomFamily: AtomIO.AtomFamily<T, K>,\n\ttransform: JsonInterface<T, J>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.SelectorFamily<J, K> => {\n\tconst jsonFamily = createSelectorFamily<J, K>(\n\t\t{\n\t\t\tkey: `${atomFamily.key}:JSON`,\n\t\t\tget: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),\n\t\t\tset: (key) => ({ set }, newValue) =>\n\t\t\t\tset(atomFamily(key), transform.fromJson(newValue)),\n\t\t},\n\t\tstore,\n\t)\n\tatomFamily.subject.subscribe(\n\t\t`store=${store.config.name}::json-selector-family`,\n\t\t(token) => {\n\t\t\tif (token.family) {\n\t\t\t\tjsonFamily(parseJson(token.family.subKey) as K)\n\t\t\t}\n\t\t},\n\t)\n\treturn jsonFamily\n}\n"]}
|
package/json/dist/index.mjs
CHANGED
|
@@ -1,7 +1,78 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createSelector, IMPLICIT, createSelectorFamily } from 'atom.io/internal';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// ../../anvl/src/json/json-interface.ts
|
|
4
|
+
var stringSetJsonInterface = {
|
|
5
|
+
toJson: (stringSet) => Array.from(stringSet),
|
|
6
|
+
fromJson: (json) => new Set(json)
|
|
7
|
+
};
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
// ../../anvl/src/json/index.ts
|
|
10
|
+
var parseJson = (str) => JSON.parse(str);
|
|
11
|
+
var stringifyJson = (json) => JSON.stringify(json);
|
|
12
|
+
var JSON_TYPE_NAMES = [
|
|
13
|
+
`array`,
|
|
14
|
+
`boolean`,
|
|
15
|
+
`null`,
|
|
16
|
+
`number`,
|
|
17
|
+
`object`,
|
|
18
|
+
`string`
|
|
19
|
+
];
|
|
20
|
+
var JSON_DEFAULTS = {
|
|
21
|
+
array: [],
|
|
22
|
+
boolean: false,
|
|
23
|
+
null: null,
|
|
24
|
+
number: 0,
|
|
25
|
+
object: {},
|
|
26
|
+
string: ``
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// ../../anvl/src/primitive/index.ts
|
|
30
|
+
var isString = (input) => {
|
|
31
|
+
return typeof input === `string`;
|
|
32
|
+
};
|
|
33
|
+
var isNumber = (input) => {
|
|
34
|
+
return typeof input === `number`;
|
|
35
|
+
};
|
|
36
|
+
var isBoolean = (input) => {
|
|
37
|
+
return typeof input === `boolean`;
|
|
38
|
+
};
|
|
39
|
+
var isNull = (input) => {
|
|
40
|
+
return input === null;
|
|
41
|
+
};
|
|
42
|
+
var isPrimitive = (input) => {
|
|
43
|
+
return isString(input) || isNumber(input) || isBoolean(input) || isNull(input);
|
|
44
|
+
};
|
|
45
|
+
var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
|
|
46
|
+
return createSelector(
|
|
47
|
+
{
|
|
48
|
+
key: `${atom.key}:JSON`,
|
|
49
|
+
get: ({ get }) => transform.toJson(get(atom)),
|
|
50
|
+
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
|
|
51
|
+
},
|
|
52
|
+
void 0,
|
|
53
|
+
store
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
var selectJsonFamily = (atomFamily, transform, store = IMPLICIT.STORE) => {
|
|
57
|
+
const jsonFamily = createSelectorFamily(
|
|
58
|
+
{
|
|
59
|
+
key: `${atomFamily.key}:JSON`,
|
|
60
|
+
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
61
|
+
set: (key) => ({ set }, newValue) => set(atomFamily(key), transform.fromJson(newValue))
|
|
62
|
+
},
|
|
63
|
+
store
|
|
64
|
+
);
|
|
65
|
+
atomFamily.subject.subscribe(
|
|
66
|
+
`store=${store.config.name}::json-selector-family`,
|
|
67
|
+
(token) => {
|
|
68
|
+
if (token.family) {
|
|
69
|
+
jsonFamily(parseJson(token.family.subKey));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
return jsonFamily;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { JSON_DEFAULTS, JSON_TYPE_NAMES, isBoolean, isNull, isNumber, isPrimitive, isString, parseJson, selectJson, selectJsonFamily, stringSetJsonInterface, stringifyJson };
|
|
6
77
|
//# sourceMappingURL=out.js.map
|
|
7
78
|
//# sourceMappingURL=index.mjs.map
|
package/json/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../anvl/src/json/json-interface.ts","../../../anvl/src/json/index.ts","../src/select-json.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../anvl/src/json/json-interface.ts","../../../anvl/src/json/index.ts","../../../anvl/src/primitive/index.ts","../src/select-json.ts","../src/select-json-family.ts"],"names":["IMPLICIT"],"mappings":";AAOO,IAAM,yBAGT;AAAA,EACH,QAAQ,CAAC,cAAc,MAAM,KAAK,SAAS;AAAA,EAC3C,UAAU,CAAC,SAAS,IAAI,IAAI,IAAI;AACjC;;;ACTO,IAAM,YAAY,CACxB,QAC4D,KAAK,MAAM,GAAG;AAIpE,IAAM,gBAAgB,CAC5B,SACoB,KAAK,UAAU,IAAI;AAIjC,IAAM,kBAAkB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAaO,IAAM,gBAA2B;AAAA,EACvC,OAAO,CAAC;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ,CAAC;AAAA,EACT,QAAQ;AACT;;;ACzCO,IAAM,WAAW,CAAC,UAAoC;AAC5D,SAAO,OAAO,UAAU;AACzB;AAEO,IAAM,WAAW,CAAC,UAAoC;AAC5D,SAAO,OAAO,UAAU;AACzB;AAEO,IAAM,YAAY,CAAC,UAAqC;AAC9D,SAAO,OAAO,UAAU;AACzB;AAEO,IAAM,SAAS,CAAC,UAAkC;AACxD,SAAO,UAAU;AAClB;AAEO,IAAM,cAAc,CAAC,UAAuC;AAClE,SAAO,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;AAC9E;;;AClBA,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAGxB,IAAM,aAAa,CACzB,MACA,WACA,QAAe,SAAS,UACK;AAC7B,SAAO;AAAA,IACN;AAAA,MACC,KAAK,GAAG,KAAK,GAAG;AAAA,MAChB,KAAK,CAAC,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,IAAI,CAAC;AAAA,MAC5C,KAAK,CAAC,EAAE,IAAI,GAAG,aAAa,IAAI,MAAM,UAAU,SAAS,QAAQ,CAAC;AAAA,IACnE;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;ACnBA,SAAS,YAAAA,WAAU,4BAA4B;AAKxC,IAAM,mBAAmB,CAK/B,YACA,WACA,QAAeA,UAAS,UACS;AACjC,QAAM,aAAa;AAAA,IAClB;AAAA,MACC,KAAK,GAAG,WAAW,GAAG;AAAA,MACtB,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,WAAW,GAAG,CAAC,CAAC;AAAA,MAChE,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,aACvB,IAAI,WAAW,GAAG,GAAG,UAAU,SAAS,QAAQ,CAAC;AAAA,IACnD;AAAA,IACA;AAAA,EACD;AACA,aAAW,QAAQ;AAAA,IAClB,SAAS,MAAM,OAAO,IAAI;AAAA,IAC1B,CAAC,UAAU;AACV,UAAI,MAAM,QAAQ;AACjB,mBAAW,UAAU,MAAM,OAAO,MAAM,CAAM;AAAA,MAC/C;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR","sourcesContent":["import type { Json } from \".\"\n\nexport type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {\n\ttoJson: (t: T) => J\n\tfromJson: (json: J) => T\n}\n\nexport const stringSetJsonInterface: JsonInterface<\n\tSet<string>,\n\tJson.Array<string>\n> = {\n\ttoJson: (stringSet) => Array.from(stringSet),\n\tfromJson: (json) => new Set(json),\n}\n","export * from \"./json-interface\"\nimport type * as Json from \"./json\"\nexport { Json }\n\nexport const parseJson = <S extends Stringified<Json.Serializable>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json.Serializable => JSON.parse(str)\n\nexport type Stringified<J extends Json.Serializable> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json.Serializable>(\n\tjson: J,\n): Stringified<J> => JSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json.Serializable> {\n\tarray: Json.Array\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: Json.Object\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\n}\n","export type primitive = boolean | number | string | null\n\nexport const isString = (input: unknown): input is string => {\n\treturn typeof input === `string`\n}\n\nexport const isNumber = (input: unknown): input is number => {\n\treturn typeof input === `number`\n}\n\nexport const isBoolean = (input: unknown): input is boolean => {\n\treturn typeof input === `boolean`\n}\n\nexport const isNull = (input: unknown): input is null => {\n\treturn input === null\n}\n\nexport const isPrimitive = (input: unknown): input is primitive => {\n\treturn isString(input) || isNumber(input) || isBoolean(input) || isNull(input)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createSelector } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \".\"\n\nexport const selectJson = <T, J extends Json.Serializable>(\n\tatom: AtomIO.AtomToken<T>,\n\ttransform: JsonInterface<T, J>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.SelectorToken<J> => {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `${atom.key}:JSON`,\n\t\t\tget: ({ get }) => transform.toJson(get(atom)),\n\t\t\tset: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelectorFamily } from \"atom.io/internal\"\n\nimport type { Json, JsonInterface } from \".\"\nimport { parseJson } from \".\"\n\nexport const selectJsonFamily = <\n\tT,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(\n\tatomFamily: AtomIO.AtomFamily<T, K>,\n\ttransform: JsonInterface<T, J>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.SelectorFamily<J, K> => {\n\tconst jsonFamily = createSelectorFamily<J, K>(\n\t\t{\n\t\t\tkey: `${atomFamily.key}:JSON`,\n\t\t\tget: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),\n\t\t\tset: (key) => ({ set }, newValue) =>\n\t\t\t\tset(atomFamily(key), transform.fromJson(newValue)),\n\t\t},\n\t\tstore,\n\t)\n\tatomFamily.subject.subscribe(\n\t\t`store=${store.config.name}::json-selector-family`,\n\t\t(token) => {\n\t\t\tif (token.family) {\n\t\t\t\tjsonFamily(parseJson(token.family.subKey) as K)\n\t\t\t}\n\t\t},\n\t)\n\treturn jsonFamily\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as AtomIO from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { IMPLICIT, createSelectorFamily } from "atom.io/internal"
|
|
4
|
+
|
|
5
|
+
import type { Json, JsonInterface } from "."
|
|
6
|
+
import { parseJson } from "."
|
|
7
|
+
|
|
8
|
+
export const selectJsonFamily = <
|
|
9
|
+
T,
|
|
10
|
+
J extends Json.Serializable,
|
|
11
|
+
K extends Json.Serializable,
|
|
12
|
+
>(
|
|
13
|
+
atomFamily: AtomIO.AtomFamily<T, K>,
|
|
14
|
+
transform: JsonInterface<T, J>,
|
|
15
|
+
store: Store = IMPLICIT.STORE,
|
|
16
|
+
): AtomIO.SelectorFamily<J, K> => {
|
|
17
|
+
const jsonFamily = createSelectorFamily<J, K>(
|
|
18
|
+
{
|
|
19
|
+
key: `${atomFamily.key}:JSON`,
|
|
20
|
+
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
21
|
+
set: (key) => ({ set }, newValue) =>
|
|
22
|
+
set(atomFamily(key), transform.fromJson(newValue)),
|
|
23
|
+
},
|
|
24
|
+
store,
|
|
25
|
+
)
|
|
26
|
+
atomFamily.subject.subscribe(
|
|
27
|
+
`store=${store.config.name}::json-selector-family`,
|
|
28
|
+
(token) => {
|
|
29
|
+
if (token.family) {
|
|
30
|
+
jsonFamily(parseJson(token.family.subKey) as K)
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
)
|
|
34
|
+
return jsonFamily
|
|
35
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as AtomIO from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { IMPLICIT } from "atom.io/internal"
|
|
4
|
+
|
|
5
|
+
import { createSelector } from "atom.io/internal"
|
|
6
|
+
import type { Json, JsonInterface } from "."
|
|
7
|
+
|
|
8
|
+
export const selectJson = <T, J extends Json.Serializable>(
|
|
9
|
+
atom: AtomIO.AtomToken<T>,
|
|
10
|
+
transform: JsonInterface<T, J>,
|
|
11
|
+
store: Store = IMPLICIT.STORE,
|
|
12
|
+
): AtomIO.SelectorToken<J> => {
|
|
13
|
+
return createSelector(
|
|
14
|
+
{
|
|
15
|
+
key: `${atom.key}:JSON`,
|
|
16
|
+
get: ({ get }) => transform.toJson(get(atom)),
|
|
17
|
+
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue)),
|
|
18
|
+
},
|
|
19
|
+
undefined,
|
|
20
|
+
store,
|
|
21
|
+
)
|
|
22
|
+
}
|