atom.io 0.15.0 → 0.15.1

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.
Files changed (36) hide show
  1. package/data/dist/index.cjs +21 -5
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.ts +18 -8
  4. package/data/dist/index.js +21 -5
  5. package/data/dist/index.js.map +1 -1
  6. package/data/src/join.ts +58 -20
  7. package/internal/dist/index.cjs +3 -1
  8. package/internal/dist/index.cjs.map +1 -1
  9. package/internal/dist/index.js +3 -1
  10. package/internal/dist/index.js.map +1 -1
  11. package/internal/src/families/create-readonly-selector-family.ts +3 -1
  12. package/package.json +2 -2
  13. package/realtime-client/dist/index.cjs +3 -0
  14. package/realtime-client/dist/index.cjs.map +1 -1
  15. package/realtime-client/dist/index.d.ts +3 -3
  16. package/realtime-client/dist/index.js +3 -0
  17. package/realtime-client/dist/index.js.map +1 -1
  18. package/realtime-client/src/index.ts +6 -6
  19. package/realtime-client/src/{use-pull-family-member.ts → pull-family-member.ts} +1 -1
  20. package/realtime-client/src/{use-pull-mutable-family-member.ts → pull-mutable-family-member.ts} +1 -1
  21. package/realtime-client/src/{use-pull-mutable.ts → pull-mutable.ts} +1 -1
  22. package/realtime-client/src/{use-server-action.ts → server-action.ts} +3 -0
  23. package/realtime-react/dist/index.cjs +31 -17
  24. package/realtime-react/dist/index.cjs.map +1 -1
  25. package/realtime-react/dist/index.d.ts +3 -3
  26. package/realtime-react/dist/index.js +31 -17
  27. package/realtime-react/dist/index.js.map +1 -1
  28. package/realtime-react/src/realtime-context.tsx +2 -3
  29. package/realtime-react/src/use-pull-family-member.ts +6 -2
  30. package/realtime-react/src/use-pull-mutable-family-member.ts +5 -4
  31. package/realtime-react/src/use-pull-mutable.ts +6 -2
  32. package/realtime-react/src/use-pull.ts +5 -1
  33. package/realtime-react/src/use-push.ts +5 -4
  34. package/realtime-react/src/use-server-action.ts +5 -4
  35. /package/realtime-client/src/{use-pull.ts → pull.ts} +0 -0
  36. /package/realtime-client/src/{use-push.ts → push.ts} +0 -0
package/data/src/join.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  import type {
3
3
  AtomFamily,
4
+ MutableAtomFamily,
4
5
  Read,
5
6
  SelectorFamily,
6
7
  Transactors,
@@ -16,6 +17,7 @@ import {
16
17
  getJsonFamily,
17
18
  } from "atom.io/internal"
18
19
  import type { Json } from "atom.io/json"
20
+ import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
19
21
  import { SetRTX } from "atom.io/transceivers/set-rtx"
20
22
 
21
23
  import type {
@@ -56,7 +58,7 @@ export type JoinState<
56
58
  readonly [AB in ASide | BSide as AB extends ASide
57
59
  ? `${AB}EntryOf${Capitalize<BSide>}`
58
60
  : `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<
59
- [string, Content] | undefined,
61
+ [string, Content] | null,
60
62
  string
61
63
  >
62
64
  }
@@ -64,7 +66,7 @@ export type JoinState<
64
66
  readonly [AB in ASide | BSide as AB extends ASide
65
67
  ? `${AB}KeyOf${Capitalize<BSide>}`
66
68
  : `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<
67
- string | undefined,
69
+ string | null,
68
70
  string
69
71
  >
70
72
  }
@@ -72,7 +74,7 @@ export type JoinState<
72
74
  ? (Content extends Json.Object
73
75
  ? {
74
76
  readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<
75
- [string, Content] | undefined,
77
+ [string, Content] | null,
76
78
  string
77
79
  >
78
80
  } & {
@@ -83,7 +85,7 @@ export type JoinState<
83
85
  }
84
86
  : {}) & {
85
87
  readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<
86
- string | undefined,
88
+ string | null,
87
89
  string
88
90
  >
89
91
  } & {
@@ -121,6 +123,13 @@ export class Join<
121
123
  private transactors: Transactors = TRANSACTORS
122
124
  public relations: Junction<ASide, BSide, Content>
123
125
  public findState: JoinState<ASide, BSide, Cardinality, Content>
126
+ public core: {
127
+ findRelatedKeysState: MutableAtomFamily<
128
+ SetRTX<string>,
129
+ SetRTXJson<string>,
130
+ string
131
+ >
132
+ }
124
133
  public transact(
125
134
  transactors: Transactors,
126
135
  run: (join: Join<ASide, BSide, Cardinality, Content>) => void,
@@ -138,18 +147,19 @@ export class Join<
138
147
  const b: BSide = options.between[1]
139
148
  const findRelatedKeysState = createMutableAtomFamily<
140
149
  SetRTX<string>,
141
- string[],
150
+ SetRTXJson<string>,
142
151
  string
143
152
  >(
144
153
  {
145
154
  key: `${options.key}/relatedKeys`,
146
155
  default: () => new SetRTX(),
147
156
  mutable: true,
148
- fromJson: (json) => new SetRTX(json),
149
- toJson: (set) => [...set],
157
+ fromJson: (json) => SetRTX.fromJSON(json),
158
+ toJson: (set) => set.toJSON(),
150
159
  },
151
160
  store,
152
161
  )
162
+ this.core = { findRelatedKeysState }
153
163
  const getRelatedKeys: Read<(key: string) => SetRTX<string>> = (
154
164
  { get },
155
165
  key,
@@ -240,10 +250,8 @@ export class Join<
240
250
  },
241
251
  store,
242
252
  )
243
- const getContent: Read<(key: string) => Content | undefined> = (
244
- { get },
245
- key,
246
- ) => get(findContentState(key))
253
+ const getContent: Read<(key: string) => Content | null> = ({ get }, key) =>
254
+ get(findContentState(key))
247
255
  const setContent: Write<(key: string, content: Content) => void> = (
248
256
  transactors,
249
257
  key,
@@ -277,7 +285,7 @@ export class Join<
277
285
  })
278
286
 
279
287
  const createSingleKeyStateFamily = () =>
280
- createSelectorFamily<string | undefined, string>(
288
+ createSelectorFamily<string | null, string>(
281
289
  {
282
290
  key: `${options.key}/singleRelatedKey`,
283
291
  get:
@@ -287,14 +295,28 @@ export class Join<
287
295
  for (const relatedKey of relatedKeys) {
288
296
  return relatedKey
289
297
  }
298
+ return null
290
299
  },
291
300
  },
292
301
  store,
293
302
  )
294
- const getMultipleKeyStateFamily = () =>
295
- getJsonFamily(findRelatedKeysState, store)
303
+ const getMultipleKeyStateFamily = () => {
304
+ return createSelectorFamily<string[], string>(
305
+ {
306
+ key: `${options.key}/multipleRelatedKeys`,
307
+ get:
308
+ (key) =>
309
+ ({ get }) => {
310
+ const jsonFamily = getJsonFamily(findRelatedKeysState, store)
311
+ const json = get(jsonFamily(key))
312
+ return json.members
313
+ },
314
+ },
315
+ store,
316
+ )
317
+ }
296
318
  const createSingleEntryStateFamily = () =>
297
- createSelectorFamily<[string, Content] | undefined, string>(
319
+ createSelectorFamily<[string, Content] | null, string>(
298
320
  {
299
321
  key: `${options.key}/singleRelatedEntry`,
300
322
  get:
@@ -305,6 +327,7 @@ export class Join<
305
327
  const contentKey = relations.makeContentKey(key, relatedKey)
306
328
  return [relatedKey, get(findContentState(contentKey))]
307
329
  }
330
+ return null
308
331
  },
309
332
  },
310
333
  store,
@@ -316,8 +339,9 @@ export class Join<
316
339
  get:
317
340
  (key) =>
318
341
  ({ get }) => {
319
- const relatedKeys = get(findRelatedKeysState(key))
320
- return [...relatedKeys].map((relatedKey) => {
342
+ const jsonFamily = getJsonFamily(findRelatedKeysState, store)
343
+ const json = get(jsonFamily(key))
344
+ return json.members.map((relatedKey) => {
321
345
  const contentKey = relations.makeContentKey(key, relatedKey)
322
346
  return [relatedKey, get(findContentState(contentKey))]
323
347
  })
@@ -415,12 +439,19 @@ export function join<
415
439
  defaultContent?: undefined,
416
440
  store?: Store,
417
441
  ): {
418
- relations: Junction<ASide, BSide, null>
419
- findState: JoinState<ASide, BSide, Cardinality, null>
420
- transact: (
442
+ readonly relations: Junction<ASide, BSide, null>
443
+ readonly findState: JoinState<ASide, BSide, Cardinality, null>
444
+ readonly transact: (
421
445
  transactors: Transactors,
422
446
  run: (join: Join<ASide, BSide, Cardinality, null>) => void,
423
447
  ) => void
448
+ readonly core: {
449
+ readonly findRelatedKeysState: MutableAtomFamily<
450
+ SetRTX<string>,
451
+ SetRTXJson<string>,
452
+ string
453
+ >
454
+ }
424
455
  }
425
456
  export function join<
426
457
  const ASide extends string,
@@ -438,6 +469,13 @@ export function join<
438
469
  transactors: Transactors,
439
470
  run: (join: Join<ASide, BSide, Cardinality, Content>) => void,
440
471
  ) => void
472
+ readonly core: {
473
+ readonly findRelatedKeysState: MutableAtomFamily<
474
+ SetRTX<string>,
475
+ SetRTXJson<string>,
476
+ string
477
+ >
478
+ }
441
479
  }
442
480
  export function join<
443
481
  ASide extends string,
@@ -1434,7 +1434,7 @@ function createAtomFamily(options, store) {
1434
1434
  }
1435
1435
  function createReadonlySelectorFamily(options, store) {
1436
1436
  const subject = new Subject();
1437
- return Object.assign(
1437
+ const readonlySelectorFamily = Object.assign(
1438
1438
  (key) => {
1439
1439
  const target = newest(store);
1440
1440
  const subKey = json.stringifyJson(key);
@@ -1460,6 +1460,8 @@ function createReadonlySelectorFamily(options, store) {
1460
1460
  install: (store2) => createReadonlySelectorFamily(options, store2)
1461
1461
  }
1462
1462
  );
1463
+ store.families.set(options.key, readonlySelectorFamily);
1464
+ return readonlySelectorFamily;
1463
1465
  }
1464
1466
  function createSelectorFamily(options, store) {
1465
1467
  const isReadonly = !(`set` in options);