@minca/core 0.1.14 → 0.1.15

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 (132) hide show
  1. package/README.md +2 -2
  2. package/dist/files/space-files.d.ts +15 -3
  3. package/dist/files/space-files.d.ts.map +1 -1
  4. package/dist/files/space-files.js +225 -37
  5. package/dist/files/space-files.js.map +1 -1
  6. package/dist/network/relay-minca.d.ts +12 -1
  7. package/dist/network/relay-minca.d.ts.map +1 -1
  8. package/dist/network/relay-minca.js +14 -6
  9. package/dist/network/relay-minca.js.map +1 -1
  10. package/dist/network/relay-nostr.d.ts +14 -3
  11. package/dist/network/relay-nostr.d.ts.map +1 -1
  12. package/dist/network/relay-nostr.js +11 -9
  13. package/dist/network/relay-nostr.js.map +1 -1
  14. package/dist/network/relays.d.ts +26 -17
  15. package/dist/network/relays.d.ts.map +1 -1
  16. package/dist/network/relays.js +21 -28
  17. package/dist/network/relays.js.map +1 -1
  18. package/dist/network/rendezvous.d.ts +1 -1
  19. package/dist/network/rendezvous.d.ts.map +1 -1
  20. package/dist/network/rendezvous.js +2 -2
  21. package/dist/network/rendezvous.js.map +1 -1
  22. package/dist/node/actions.d.ts.map +1 -1
  23. package/dist/node/actions.js +6 -1
  24. package/dist/node/actions.js.map +1 -1
  25. package/dist/node/node.d.ts.map +1 -1
  26. package/dist/node/node.js +7 -7
  27. package/dist/node/node.js.map +1 -1
  28. package/dist/node/space-runtime.d.ts +1 -1
  29. package/dist/node/space-runtime.d.ts.map +1 -1
  30. package/dist/node/space-runtime.js +17 -5
  31. package/dist/node/space-runtime.js.map +1 -1
  32. package/dist/node/types.d.ts +4 -3
  33. package/dist/node/types.d.ts.map +1 -1
  34. package/dist/schema/collection-def.d.ts.map +1 -1
  35. package/dist/schema/collection-def.js +16 -5
  36. package/dist/schema/collection-def.js.map +1 -1
  37. package/dist/schemas/automations.d.ts +8 -0
  38. package/dist/schemas/automations.d.ts.map +1 -1
  39. package/dist/schemas/connectors.d.ts +12 -0
  40. package/dist/schemas/connectors.d.ts.map +1 -1
  41. package/dist/schemas/fragments.d.ts +22 -2
  42. package/dist/schemas/fragments.d.ts.map +1 -1
  43. package/dist/schemas/fragments.js +20 -12
  44. package/dist/schemas/fragments.js.map +1 -1
  45. package/dist/schemas/library/annotations.d.ts +30 -0
  46. package/dist/schemas/library/annotations.d.ts.map +1 -1
  47. package/dist/schemas/library/annotations.js +1 -0
  48. package/dist/schemas/library/annotations.js.map +1 -1
  49. package/dist/schemas/library/community.d.ts +28 -0
  50. package/dist/schemas/library/community.d.ts.map +1 -1
  51. package/dist/schemas/library/life.d.ts +62 -2
  52. package/dist/schemas/library/life.d.ts.map +1 -1
  53. package/dist/schemas/library/media.d.ts +36 -0
  54. package/dist/schemas/library/media.d.ts.map +1 -1
  55. package/dist/schemas/library/money.d.ts +74 -2
  56. package/dist/schemas/library/money.d.ts.map +1 -1
  57. package/dist/schemas/library/planning.d.ts +56 -0
  58. package/dist/schemas/library/planning.d.ts.map +1 -1
  59. package/dist/schemas/library/publishing.d.ts +80 -4
  60. package/dist/schemas/library/publishing.d.ts.map +1 -1
  61. package/dist/schemas/library/social.d.ts +44 -0
  62. package/dist/schemas/library/social.d.ts.map +1 -1
  63. package/docs/README.md +2 -2
  64. package/docs/actions.md +47 -20
  65. package/docs/blueprints-and-guides.md +41 -13
  66. package/docs/building-an-app.md +4 -4
  67. package/docs/collections.md +31 -3
  68. package/docs/node.md +14 -12
  69. package/docs/standard-library.md +26 -25
  70. package/docs/storage.md +33 -10
  71. package/package.json +2 -21
  72. package/dist/calls/calls.d.ts +0 -140
  73. package/dist/calls/calls.d.ts.map +0 -1
  74. package/dist/calls/calls.js +0 -861
  75. package/dist/calls/calls.js.map +0 -1
  76. package/dist/calls/index.d.ts +0 -4
  77. package/dist/calls/index.d.ts.map +0 -1
  78. package/dist/calls/index.js +0 -3
  79. package/dist/calls/index.js.map +0 -1
  80. package/dist/react/context.d.ts +0 -81
  81. package/dist/react/context.d.ts.map +0 -1
  82. package/dist/react/context.js +0 -97
  83. package/dist/react/context.js.map +0 -1
  84. package/dist/react/follow.d.ts +0 -11
  85. package/dist/react/follow.d.ts.map +0 -1
  86. package/dist/react/follow.js +0 -7
  87. package/dist/react/follow.js.map +0 -1
  88. package/dist/react/index.d.ts +0 -44
  89. package/dist/react/index.d.ts.map +0 -1
  90. package/dist/react/index.js +0 -40
  91. package/dist/react/index.js.map +0 -1
  92. package/dist/react/minca-auth.d.ts +0 -19
  93. package/dist/react/minca-auth.d.ts.map +0 -1
  94. package/dist/react/minca-auth.js +0 -36
  95. package/dist/react/minca-auth.js.map +0 -1
  96. package/dist/react/use-calls.d.ts +0 -21
  97. package/dist/react/use-calls.d.ts.map +0 -1
  98. package/dist/react/use-calls.js +0 -39
  99. package/dist/react/use-calls.js.map +0 -1
  100. package/dist/react/use-invite-link.d.ts +0 -24
  101. package/dist/react/use-invite-link.d.ts.map +0 -1
  102. package/dist/react/use-invite-link.js +0 -62
  103. package/dist/react/use-invite-link.js.map +0 -1
  104. package/dist/react/use-live.d.ts +0 -16
  105. package/dist/react/use-live.d.ts.map +0 -1
  106. package/dist/react/use-live.js +0 -56
  107. package/dist/react/use-live.js.map +0 -1
  108. package/dist/react/use-my-name.d.ts +0 -12
  109. package/dist/react/use-my-name.d.ts.map +0 -1
  110. package/dist/react/use-my-name.js +0 -38
  111. package/dist/react/use-my-name.js.map +0 -1
  112. package/dist/react/use-names.d.ts +0 -7
  113. package/dist/react/use-names.d.ts.map +0 -1
  114. package/dist/react/use-names.js +0 -13
  115. package/dist/react/use-names.js.map +0 -1
  116. package/dist/react/use-network.d.ts +0 -9
  117. package/dist/react/use-network.d.ts.map +0 -1
  118. package/dist/react/use-network.js +0 -33
  119. package/dist/react/use-network.js.map +0 -1
  120. package/dist/react/use-query.d.ts +0 -14
  121. package/dist/react/use-query.d.ts.map +0 -1
  122. package/dist/react/use-query.js +0 -26
  123. package/dist/react/use-query.js.map +0 -1
  124. package/dist/react/use-space.d.ts +0 -29
  125. package/dist/react/use-space.d.ts.map +0 -1
  126. package/dist/react/use-space.js +0 -57
  127. package/dist/react/use-space.js.map +0 -1
  128. package/dist/react/use-spaces.d.ts +0 -29
  129. package/dist/react/use-spaces.d.ts.map +0 -1
  130. package/dist/react/use-spaces.js +0 -78
  131. package/dist/react/use-spaces.js.map +0 -1
  132. package/docs/calls.md +0 -189
@@ -1,62 +0,0 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { useNode } from './context.js';
3
- /**
4
- * Invite links carry the invite in the URL fragment (`#invite=…`), which
5
- * browsers never send to a server, including the one hosting the page. For a
6
- * private space the invite holds the space key, so it must never go anywhere
7
- * else.
8
- */
9
- const IN_LINK = /[#&]invite=([^&]+)/;
10
- /**
11
- * A link that opens this page with an invite in it.
12
- *
13
- * ```ts
14
- * inviteLink(await node.spaces.invite(space.id, { short: true })) // https://app.example/#invite=…
15
- * ```
16
- */
17
- export function inviteLink(invite, page) {
18
- const { origin, pathname } = globalThis.location;
19
- return `${page ?? origin + pathname}#invite=${invite}`;
20
- }
21
- /** The invite in a link someone pasted, or the text itself when it is a bare invite */
22
- export function inviteFromLink(value) {
23
- const trimmed = value.trim();
24
- return IN_LINK.exec(trimmed)?.[1] ?? trimmed;
25
- }
26
- /**
27
- * The invite this page was opened with, if any, and what it is for: the
28
- * space's name, the role it gives, who sent it. `dismiss` takes it out of the
29
- * address bar, once joined or declined, so a reload doesn't offer it again.
30
- * `problem` says why an invite could not be read.
31
- */
32
- export function useInviteLink() {
33
- const node = useNode();
34
- const [invite, setInvite] = useState(() => IN_LINK.exec(globalThis.location?.hash ?? '')?.[1] ?? null);
35
- // A short link is fetched from its mailboxes, so what it is for arrives a moment later.
36
- // What arrives is kept with the invite it is for: a newer invite shows nothing until its own does.
37
- const [found, setFound] = useState(null);
38
- useEffect(() => {
39
- if (!invite)
40
- return;
41
- let current = true;
42
- node.spaces.preview(invite).then((preview) => current && setFound({ invite, preview, problem: null }), (error) => current &&
43
- setFound({
44
- invite,
45
- preview: null,
46
- problem: error instanceof Error ? error.message : 'This invite could not be read',
47
- }));
48
- return () => {
49
- current = false;
50
- };
51
- }, [node, invite]);
52
- const read = found && found.invite === invite
53
- ? { preview: found.preview, problem: found.problem }
54
- : { preview: null, problem: null };
55
- const dismiss = useCallback(() => {
56
- setInvite(null);
57
- const { pathname, search } = globalThis.location;
58
- globalThis.history.replaceState(null, '', pathname + search);
59
- }, []);
60
- return { invite, ...read, dismiss };
61
- }
62
- //# sourceMappingURL=use-invite-link.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-invite-link.js","sourceRoot":"","sources":["../../src/react/use-invite-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,OAAO,GAAG,oBAAoB,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,IAAa;IACtD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC;IACjD,OAAO,GAAG,IAAI,IAAI,MAAM,GAAG,QAAQ,WAAW,MAAM,EAAE,CAAC;AACzD,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IAM3B,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,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,CAAC;QACjD,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAC;IAC/D,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC"}
@@ -1,16 +0,0 @@
1
- import type { P2PNode } from '../node/types.js';
2
- /**
3
- * Loads something from a space, and loads it again whenever that space's
4
- * records or connection change — locally or by sync. One load at a time; a
5
- * change during a load triggers one more, never a queue of stale ones.
6
- *
7
- * The named hooks (`useRecord`, `useCollections`, …) cover the usual reads;
8
- * this is for anything else.
9
- *
10
- * @param spaceId The space to follow
11
- * @param load What to read, given the node
12
- * @param deps When these change, start over
13
- * @returns The latest value, or undefined until the first load finishes
14
- */
15
- export declare function useLive<T>(spaceId: string, load: (node: P2PNode) => Promise<T>, deps: ReadonlyArray<unknown>): T | undefined;
16
- //# sourceMappingURL=use-live.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-live.d.ts","sourceRoot":"","sources":["../../src/react/use-live.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,EACnC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,GAC3B,CAAC,GAAG,SAAS,CAsCf"}
@@ -1,56 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { useNode } from './context.js';
3
- /**
4
- * Loads something from a space, and loads it again whenever that space's
5
- * records or connection change — locally or by sync. One load at a time; a
6
- * change during a load triggers one more, never a queue of stale ones.
7
- *
8
- * The named hooks (`useRecord`, `useCollections`, …) cover the usual reads;
9
- * this is for anything else.
10
- *
11
- * @param spaceId The space to follow
12
- * @param load What to read, given the node
13
- * @param deps When these change, start over
14
- * @returns The latest value, or undefined until the first load finishes
15
- */
16
- export function useLive(spaceId, load, deps) {
17
- const node = useNode();
18
- const [value, setValue] = useState(undefined);
19
- useEffect(() => {
20
- let stopped = false;
21
- let running = false;
22
- let again = false;
23
- const run = async () => {
24
- if (running) {
25
- again = true;
26
- return;
27
- }
28
- running = true;
29
- do {
30
- again = false;
31
- try {
32
- const next = await load(node);
33
- if (!stopped)
34
- setValue(next);
35
- }
36
- catch (error) {
37
- console.warn('useLive:', error);
38
- }
39
- } while (again && !stopped);
40
- running = false;
41
- };
42
- void run();
43
- const unsubscribe = node.subscribe((event) => {
44
- if ('space' in event && event.space === spaceId)
45
- void run();
46
- });
47
- return () => {
48
- stopped = true;
49
- unsubscribe();
50
- };
51
- // The caller names what `load` depends on, as with useEffect.
52
- // eslint-disable-next-line react-hooks/exhaustive-deps
53
- }, [node, spaceId, ...deps]);
54
- return value;
55
- }
56
- //# sourceMappingURL=use-live.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-live.js","sourceRoot":"","sources":["../../src/react/use-live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CACrB,OAAe,EACf,IAAmC,EACnC,IAA4B;IAE5B,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,SAAS,CAAC,CAAC;IAE7D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;YACrB,IAAI,OAAO,EAAE,CAAC;gBACZ,KAAK,GAAG,IAAI,CAAC;gBACb,OAAO;YACT,CAAC;YACD,OAAO,GAAG,IAAI,CAAC;YACf,GAAG,CAAC;gBACF,KAAK,GAAG,KAAK,CAAC;gBACd,IAAI,CAAC;oBACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC9B,IAAI,CAAC,OAAO;wBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,QAAQ,KAAK,IAAI,CAAC,OAAO,EAAE;YAC5B,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC,CAAC;QACF,KAAK,GAAG,EAAE,CAAC;QACX,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3C,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO;gBAAE,KAAK,GAAG,EAAE,CAAC;QAC9D,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,OAAO,GAAG,IAAI,CAAC;YACf,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;QACF,8DAA8D;QAC9D,uDAAuD;IACzD,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * The name others see, for asking where it matters: making or joining a
3
- * space. Starts as the account's name, so most people just carry on. `save`
4
- * puts it on the account, and the node tells every space from there, so
5
- * nobody shows up as a bare code because they never got round to settings.
6
- */
7
- export declare function useMyName(): {
8
- name: string;
9
- setName: (name: string) => void;
10
- save: () => Promise<void>;
11
- };
12
- //# sourceMappingURL=use-my-name.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-my-name.d.ts","sourceRoot":"","sources":["../../src/react/use-my-name.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,SAAS,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CA6BxG"}
@@ -1,38 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { useAccount, useNode } from './context.js';
3
- /**
4
- * The name others see, for asking where it matters: making or joining a
5
- * space. Starts as the account's name, so most people just carry on. `save`
6
- * puts it on the account, and the node tells every space from there, so
7
- * nobody shows up as a bare code because they never got round to settings.
8
- */
9
- export function useMyName() {
10
- const node = useNode();
11
- const account = useAccount();
12
- const [saved, setSaved] = useState(null);
13
- const [name, setName] = useState(account.name);
14
- useEffect(() => {
15
- let live = true;
16
- void node.account
17
- .profile()
18
- .then((profile) => {
19
- if (!live || !profile)
20
- return;
21
- setSaved(profile.name);
22
- setName((current) => (current === account.name ? profile.name : current));
23
- })
24
- .catch(() => { });
25
- return () => {
26
- live = false;
27
- };
28
- }, [node, account.name]);
29
- /** Keeps the name on the account, unless it is empty or already there */
30
- const save = async () => {
31
- const trimmed = name.trim();
32
- if (!trimmed || trimmed === saved)
33
- return;
34
- await node.account.setName(trimmed).catch(() => { });
35
- };
36
- return { name, setName, save };
37
- }
38
- //# sourceMappingURL=use-my-name.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-my-name.js","sourceRoot":"","sources":["../../src/react/use-my-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,IAAI,GAA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E,CAAC;AACjC,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Names people in a space: `name(did)` is what they call themselves there,
3
- * with the tail of their identity added when two people gave the same name
4
- * (`displayName`), so a name can never pass for someone else's.
5
- */
6
- export declare function useNames(spaceId: string): (did: string | null | undefined) => string;
7
- //# sourceMappingURL=use-names.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-names.d.ts","sourceRoot":"","sources":["../../src/react/use-names.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAAK,MAAM,CAGpF"}
@@ -1,13 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { displayName } from '../space/names.js';
3
- import { useProfiles } from './use-space.js';
4
- /**
5
- * Names people in a space: `name(did)` is what they call themselves there,
6
- * with the tail of their identity added when two people gave the same name
7
- * (`displayName`), so a name can never pass for someone else's.
8
- */
9
- export function useNames(spaceId) {
10
- const profiles = useProfiles(spaceId);
11
- return useCallback((did) => displayName(did, profiles), [profiles]);
12
- }
13
- //# sourceMappingURL=use-names.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-names.js","sourceRoot":"","sources":["../../src/react/use-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -1,9 +0,0 @@
1
- import type { MeshStatus } from '../network/mesh.js';
2
- /**
3
- * The node's relays and connections, across every space: which relays are
4
- * open, which are waiting to try again and why, and the peers connected or
5
- * being connected to. Changes as they do; `useNode().network.reconnect()`
6
- * tries a waiting relay now.
7
- */
8
- export declare function useNetwork(): MeshStatus;
9
- //# sourceMappingURL=use-network.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-network.d.ts","sourceRoot":"","sources":["../../src/react/use-network.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAOrD;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,UAAU,CAsBvC"}
@@ -1,33 +0,0 @@
1
- import { useCallback, useSyncExternalStore } from 'react';
2
- import { useNode } from './context.js';
3
- /** Each node's status as last read, so a render sees the same object until something changes */
4
- const latest = new WeakMap();
5
- /**
6
- * The node's relays and connections, across every space: which relays are
7
- * open, which are waiting to try again and why, and the peers connected or
8
- * being connected to. Changes as they do; `useNode().network.reconnect()`
9
- * tries a waiting relay now.
10
- */
11
- export function useNetwork() {
12
- const node = useNode();
13
- const subscribe = useCallback((changed) => {
14
- // Read afresh from here on: nothing told the cache while nobody listened.
15
- latest.delete(node);
16
- return node.subscribe((event) => {
17
- if (event.type !== 'network')
18
- return;
19
- latest.delete(node);
20
- changed();
21
- });
22
- }, [node]);
23
- const read = useCallback(() => {
24
- const held = latest.get(node);
25
- if (held)
26
- return held;
27
- const status = node.network.status();
28
- latest.set(node, status);
29
- return status;
30
- }, [node]);
31
- return useSyncExternalStore(subscribe, read, read);
32
- }
33
- //# sourceMappingURL=use-network.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-network.js","sourceRoot":"","sources":["../../src/react/use-network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,gGAAgG;AAChG,MAAM,MAAM,GAAG,IAAI,OAAO,EAAuB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,OAAmB,EAAE,EAAE;QACtB,0EAA0E;QAC1E,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;gBAAE,OAAO;YACrC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;IACF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACX,OAAO,oBAAoB,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC"}
@@ -1,14 +0,0 @@
1
- import { type CollectionRef, type IncludeMap, type Query, type ResultFor } from '../query/types.js';
2
- export interface QueryState<R> {
3
- /** The latest result, or null until the first one arrives. `result.complete` is false while what it needs is still on its way. */
4
- readonly result: R | null;
5
- /** Why the query failed — usually a malformed query, saying what to fix */
6
- readonly error: Error | null;
7
- }
8
- /**
9
- * Runs a query and keeps it current as records change, locally or by sync.
10
- * The query is plain data, compared by value, so writing it inline is fine.
11
- * Name the collection by its definition and the result comes back typed.
12
- */
13
- export declare function useQuery<const C extends CollectionRef, const I extends IncludeMap | undefined = undefined>(spaceId: string, query: Query<C, I>): QueryState<ResultFor<C, I>>;
14
- //# sourceMappingURL=use-query.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/react/use-query.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,kIAAkI;IAClI,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,aAAa,EAAE,KAAK,CAAC,CAAC,SAAS,UAAU,GAAG,SAAS,GAAG,SAAS,EACxG,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GACjB,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAqB7B"}
@@ -1,26 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { plainQuery, } from '../query/types.js';
3
- import { useNode } from './context.js';
4
- /**
5
- * Runs a query and keeps it current as records change, locally or by sync.
6
- * The query is plain data, compared by value, so writing it inline is fine.
7
- * Name the collection by its definition and the result comes back typed.
8
- */
9
- export function useQuery(spaceId, query) {
10
- const node = useNode();
11
- const [state, setState] = useState({ result: null, error: null });
12
- // Compared by its plain form: a definition's validator is not data.
13
- const key = JSON.stringify(plainQuery(query));
14
- useEffect(() => {
15
- // eslint-disable-next-line react-hooks/set-state-in-effect -- a new query must not show the last one's result
16
- setState({ result: null, error: null });
17
- return node.records.watch(spaceId,
18
- // The plain form `key` was made from: data a connection can send on to the home.
19
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- parsed from plainQuery's output
20
- JSON.parse(key),
21
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- typed from the query, as records.query is
22
- (result) => setState({ result: result, error: null }), (error) => setState((previous) => ({ result: previous.result, error })));
23
- }, [node, spaceId, key]);
24
- return state;
25
- }
26
- //# sourceMappingURL=use-query.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-query.js","sourceRoot":"","sources":["../../src/react/use-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EACL,UAAU,GAKX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AASvC;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAe,EACf,KAAkB;IAElB,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA8B,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/F,oEAAoE;IACpE,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAE9C,SAAS,CAAC,GAAG,EAAE;QACb,8GAA8G;QAC9G,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CACvB,OAAO;QACP,iFAAiF;QACjF,4GAA4G;QAC5G,IAAI,CAAC,KAAK,CAAC,GAAG,CAAU;QACxB,sHAAsH;QACtH,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAyB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EACxE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzB,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,29 +0,0 @@
1
- import type { NodeCollection, NodeRecord, SpaceAccess, SpaceProfile, SpaceStatus } from '../node/types.js';
2
- /**
3
- * Holds a space (`spaces.hold`) while the component is on screen, so it keeps syncing. Reading or writing
4
- * opens a space anyway; this is for a view that should hear from peers even
5
- * before it asks for anything.
6
- */
7
- export declare function useHoldSpace(spaceId: string): void;
8
- /** A record's current version: undefined while loading, null when there is none. */
9
- export declare function useRecord<T = unknown>(spaceId: string, key: string): NodeRecord<T> | null | undefined;
10
- /** The records whose current version points at this one — optionally in one role, or one collection. */
11
- export declare function useLinked<T = unknown>(spaceId: string, key: string, options?: {
12
- rel?: string;
13
- collection?: string;
14
- }): ReadonlyArray<NodeRecord<T>> | undefined;
15
- /** What the space holds: its kinds of things, with their schemas and counts. */
16
- export declare function useCollections(spaceId: string): ReadonlyArray<NodeCollection>;
17
- /** Who is who in the space: the name each person gave. */
18
- export declare function useProfiles(spaceId: string): ReadonlyArray<SpaceProfile>;
19
- /** Who holds what in the space — its roles, members and invites, and your own role. */
20
- export declare function useAccess(spaceId: string): SpaceAccess | undefined;
21
- /** Connection, peers, and how many records peers sent that failed checks. */
22
- export declare function useSpaceStatus(spaceId: string): SpaceStatus | undefined;
23
- /**
24
- * Whether this account may `create` in a collection (`target` = its name), or
25
- * `edit` / `delete` a record (`target` = its key). False until known — for
26
- * hiding a button rather than showing an error.
27
- */
28
- export declare function useCan(spaceId: string, action: 'create' | 'edit' | 'delete', target: string): boolean;
29
- //# sourceMappingURL=use-space.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}
@@ -1,57 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { useNode } from './context.js';
3
- import { useLive } from './use-live.js';
4
- /**
5
- * Holds a space (`spaces.hold`) while the component is on screen, so it keeps syncing. Reading or writing
6
- * opens a space anyway; this is for a view that should hear from peers even
7
- * before it asks for anything.
8
- */
9
- export function useHoldSpace(spaceId) {
10
- const node = useNode();
11
- useEffect(() => {
12
- const held = node.spaces.hold(spaceId).catch(() => null);
13
- // Let go a moment late: clicking away and straight back keeps the space syncing.
14
- return () => {
15
- setTimeout(() => void held.then((release) => release?.()), LET_GO_LATE_MS);
16
- };
17
- }, [node, spaceId]);
18
- }
19
- /** How long a space stays held after the screen showing it goes */
20
- const LET_GO_LATE_MS = 3000;
21
- /** A record's current version: undefined while loading, null when there is none. */
22
- export function useRecord(spaceId, key) {
23
- return useLive(spaceId, (node) => node.records.get(spaceId, key), [key]);
24
- }
25
- /** The records whose current version points at this one — optionally in one role, or one collection. */
26
- export function useLinked(spaceId, key, options = {}) {
27
- return useLive(spaceId, (node) => node.records.linked(spaceId, key, options), [
28
- key,
29
- options.rel,
30
- options.collection,
31
- ]);
32
- }
33
- /** What the space holds: its kinds of things, with their schemas and counts. */
34
- export function useCollections(spaceId) {
35
- return useLive(spaceId, (node) => node.collections.list(spaceId), []) ?? [];
36
- }
37
- /** Who is who in the space: the name each person gave. */
38
- export function useProfiles(spaceId) {
39
- return useLive(spaceId, (node) => node.spaces.profiles(spaceId), []) ?? [];
40
- }
41
- /** Who holds what in the space — its roles, members and invites, and your own role. */
42
- export function useAccess(spaceId) {
43
- return useLive(spaceId, (node) => node.spaces.access(spaceId), []);
44
- }
45
- /** Connection, peers, and how many records peers sent that failed checks. */
46
- export function useSpaceStatus(spaceId) {
47
- return useLive(spaceId, (node) => node.spaces.status(spaceId), []);
48
- }
49
- /**
50
- * Whether this account may `create` in a collection (`target` = its name), or
51
- * `edit` / `delete` a record (`target` = its key). False until known — for
52
- * hiding a button rather than showing an error.
53
- */
54
- export function useCan(spaceId, action, target) {
55
- return useLive(spaceId, (node) => node.records.can(spaceId, action, target), [action, target]) ?? false;
56
- }
57
- //# sourceMappingURL=use-space.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-space.js","sourceRoot":"","sources":["../../src/react/use-space.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACzD,iFAAiF;QACjF,OAAO,GAAG,EAAE;YACV,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC;QAC7E,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AACtB,CAAC;AAED,mEAAmE;AACnE,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,oFAAoF;AACpF,MAAM,UAAU,SAAS,CAAc,OAAe,EAAE,GAAW;IACjE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAI,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,GAAW,EACX,OAAO,GAA0C,EAAE;IAEn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CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC;AAC1G,CAAC"}
@@ -1,29 +0,0 @@
1
- import type { NewSpace, SpaceSummary } from '../node/types.js';
2
- export interface SpacesState {
3
- readonly spaces: ReadonlyArray<SpaceSummary>;
4
- readonly loading: boolean;
5
- readonly error: string | null;
6
- refresh(): Promise<void>;
7
- /** Makes a space; null when it failed, with `error` saying why */
8
- create(params: NewSpace): Promise<SpaceSummary | null>;
9
- /** Joins from an invite; null when it failed */
10
- join(invite: string): Promise<SpaceSummary | null>;
11
- /** Forgets a space on this device */
12
- leave(spaceId: string): Promise<void>;
13
- }
14
- export interface SpacesOptions {
15
- /**
16
- * Only spaces that define all of these collections: the spaces an app
17
- * works in, when it was given the whole account. A space still being
18
- * joined is kept, since its definitions have not arrived yet.
19
- */
20
- readonly having?: ReadonlyArray<string | {
21
- readonly name: string;
22
- }>;
23
- }
24
- /**
25
- * The account's spaces, kept current — including ones joined on another device
26
- * of the account, which the account registry brings here.
27
- */
28
- export declare function useSpaces(options?: SpacesOptions): SpacesState;
29
- //# sourceMappingURL=use-spaces.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-spaces.d.ts","sourceRoot":"","sources":["../../src/react/use-spaces.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAG/D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,kEAAkE;IAClE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACvD,gDAAgD;IAChD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACnD,qCAAqC;IACrC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,aAAkB,GAAG,WAAW,CA+ElE"}
@@ -1,78 +0,0 @@
1
- import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { useNode } from './context.js';
3
- /**
4
- * The account's spaces, kept current — including ones joined on another device
5
- * of the account, which the account registry brings here.
6
- */
7
- export function useSpaces(options = {}) {
8
- const node = useNode();
9
- const [spaces, setSpaces] = useState([]);
10
- const [loading, setLoading] = useState(true);
11
- const [error, setError] = useState(null);
12
- const having = (options.having ?? []).map((c) => (typeof c === 'string' ? c : c.name)).join('\n');
13
- // Which spaces are listed, so records arriving in one already there don't list them all again.
14
- const listed = useRef(new Set());
15
- /** Whether a space defines every collection in `having` */
16
- const fits = useCallback(async (space) => {
17
- if (!having || space.joining)
18
- return true;
19
- const defined = new Set((await node.collections.list(space.id).catch(() => []))
20
- .filter((c) => c.version !== null)
21
- .map((c) => c.name));
22
- return having.split('\n').every((name) => defined.has(name));
23
- }, [node, having]);
24
- const refresh = useCallback(async () => {
25
- try {
26
- const all = await node.spaces.list();
27
- const fit = await Promise.all(all.map(fits));
28
- const kept = all.filter((_, i) => fit[i]);
29
- listed.current = new Set(kept.filter((space) => !space.joining).map((space) => space.id));
30
- setSpaces(kept);
31
- }
32
- catch (e) {
33
- setError(e instanceof Error ? e.message : 'Could not load your spaces');
34
- }
35
- finally {
36
- setLoading(false);
37
- }
38
- }, [node, fits]);
39
- useEffect(() => {
40
- // eslint-disable-next-line react-hooks/set-state-in-effect -- the first load, then one per change
41
- void refresh();
42
- return node.subscribe((event) => {
43
- if (event.type === 'spaces')
44
- void refresh();
45
- // With `having`, a space's definitions arriving by sync can bring it into the list.
46
- else if (having && event.type === 'records' && !listed.current.has(event.space)) {
47
- void node.spaces
48
- .get(event.space)
49
- .then(async (space) => space && (await fits(space)) && refresh())
50
- .catch(() => { });
51
- }
52
- });
53
- }, [node, refresh, fits, having]);
54
- const attempt = useCallback(async (work, failed) => {
55
- setError(null);
56
- try {
57
- const done = await work();
58
- await refresh();
59
- return done;
60
- }
61
- catch (e) {
62
- setError(e instanceof Error ? e.message : failed);
63
- return null;
64
- }
65
- }, [refresh]);
66
- return {
67
- spaces,
68
- loading,
69
- error,
70
- refresh,
71
- create: (params) => attempt(() => node.spaces.create(params), 'Could not create that space'),
72
- join: (invite) => attempt(() => node.spaces.join(invite), 'Could not join that space'),
73
- leave: async (spaceId) => {
74
- await attempt(() => node.spaces.leave(spaceId), 'Could not leave that space');
75
- },
76
- };
77
- }
78
- //# sourceMappingURL=use-spaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-spaces.js","sourceRoot":"","sources":["../../src/react/use-spaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAwBvC;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,OAAO,GAAkB,EAAE;IACnD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAA8B,EAAE,CAAC,CAAC;IACtE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,M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