@estiva-app/interop 0.81.0 → 0.83.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.
@@ -975,7 +975,7 @@ const BARE_FILE_MANIFEST = {
975
975
  {
976
976
  id: 'comment',
977
977
  label: 'Comment',
978
- description: 'Say something about this file. The comment lands in the Folder the file lives in, ' +
978
+ description: 'Say something about this file. The comment lands in the team the file lives in, ' +
979
979
  'and is what every reader of the file sees under it.',
980
980
  effect: 'writes',
981
981
  appliesTo: [String(KIND_BARE_FILE)],
@@ -985,7 +985,7 @@ const BARE_FILE_MANIFEST = {
985
985
  {
986
986
  id: 'rename',
987
987
  label: 'Rename',
988
- description: 'Give this file a new title. A change event, so anyone in the Folder may, and every app ' +
988
+ description: 'Give this file a new title. A change event, so anyone in the team may, and every app ' +
989
989
  'reading the file folds it into the title.',
990
990
  effect: 'writes',
991
991
  appliesTo: [String(KIND_BARE_FILE)],
@@ -1002,7 +1002,7 @@ const BARE_FILE_MANIFEST = {
1002
1002
  id: 'summarize',
1003
1003
  label: 'Summary',
1004
1004
  description: "Set this file's summary: one or two sentences of plain text, about 240 characters, shown under its " +
1005
- 'title wherever it is met in one line. A change event, so anyone in the Folder may; an empty value clears it.',
1005
+ 'title wherever it is met in one line. A change event, so anyone in the team may; an empty value clears it.',
1006
1006
  effect: 'writes',
1007
1007
  appliesTo: [String(KIND_BARE_FILE)],
1008
1008
  emits: { kind: 1851, field: SUMMARY_FIELD },
@@ -1018,8 +1018,8 @@ const BARE_FILE_MANIFEST = {
1018
1018
  {
1019
1019
  id: 'move',
1020
1020
  label: 'Move',
1021
- description: "Put this file under another file in the same Folder, or back at the top. A change event, so anyone in " +
1022
- 'the Folder may; who can read the file does not change.',
1021
+ description: "Put this file under another file in the same team, or back at the top. A change event, so anyone in " +
1022
+ 'the team may; who can read the file does not change.',
1023
1023
  effect: 'writes',
1024
1024
  appliesTo: [String(KIND_BARE_FILE)],
1025
1025
  emits: { kind: 1851, field: 'parent' },
@@ -1103,8 +1103,8 @@ export const FOLDER_ACTIONS_ADDRESS = 'spec:3.2';
1103
1103
  */
1104
1104
  const FOLDER_CREATOR = {
1105
1105
  manifest: {
1106
- name: 'Folder',
1107
- about: 'What every app may do in a Folder, whichever app made it.',
1106
+ name: 'Team',
1107
+ about: 'What every app may do in a team, whichever app made it.',
1108
1108
  projections: {
1109
1109
  [String(KIND_BARE_FILE)]: BARE_FILE_MANIFEST.projections[String(KIND_BARE_FILE)],
1110
1110
  [String(KIND_MESSAGE)]: BARE_FILE_MANIFEST.projections[String(KIND_MESSAGE)],
@@ -1113,8 +1113,8 @@ const FOLDER_CREATOR = {
1113
1113
  {
1114
1114
  id: 'create-file',
1115
1115
  label: 'New file',
1116
- description: 'Put a new file in this Folder: a title and, if you have one, a short summary. Everyone who can read the Folder can read ' +
1117
- 'it, and the Folder lists it straight away. The app opening files calls it by its own word — Peek says topic.',
1116
+ description: 'Put a new file in this team: a title and, if you have one, a short summary. Everyone who can read the team can read ' +
1117
+ 'it, and the team lists it straight away. The app opening files calls it by its own word — Peek says topic.',
1118
1118
  effect: 'writes',
1119
1119
  appliesTo: String(KIND_CHANNEL_METADATA),
1120
1120
  emits: { kind: KIND_BARE_FILE, listed: true },
@@ -1135,9 +1135,9 @@ const FOLDER_CREATOR = {
1135
1135
  {
1136
1136
  id: 'start-a-conversation',
1137
1137
  label: 'Start a conversation',
1138
- description: 'Start a new conversation in this Folder, as a root message that people can then reply to. ' +
1138
+ description: 'Start a new conversation in this team, as a root message that people can then reply to. ' +
1139
1139
  'Use when something is worth its own thread rather than an answer inside an existing one — ' +
1140
- 'this cannot reply to a message. Everyone who can read the Folder reads it.',
1140
+ 'this cannot reply to a message. Everyone who can read the team reads it.',
1141
1141
  effect: 'writes',
1142
1142
  appliesTo: String(KIND_CHANNEL_METADATA),
1143
1143
  emits: { kind: KIND_MESSAGE, toAddressOf: 'self' },
@@ -1159,7 +1159,8 @@ const FOLDER_CREATOR = {
1159
1159
  * No app owns a Folder, so no `kind:31990` may claim `39000`; until this
1160
1160
  * release Peek's did, and every app learned a Folder's name from it. The title
1161
1161
  * is the channel record's `name`, the subtitle its `about` (the built-in
1162
- * subtitle, {@link defaultSubtitle}), and the noun "folder".
1162
+ * subtitle, {@link defaultSubtitle}), and the noun "team" (SPEC §3.2; it was
1163
+ * "folder" until every app renamed on the same day, TEA-8).
1163
1164
  *
1164
1165
  * **No `list` slot.** What a Folder holds is what its relay-signed `30890`
1165
1166
  * names, which no `children` declaration can say, and it is read by
@@ -1177,12 +1178,12 @@ const FOLDER_CREATOR = {
1177
1178
  * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/folders-belong-to-the-protocol.md
1178
1179
  */
1179
1180
  const FOLDER_MANIFEST = {
1180
- name: 'Folder',
1181
- about: 'A Folder no app owns: its name, its one-liner, and the files its state lists.',
1181
+ name: 'Team',
1182
+ about: 'A team no app owns: its name, its one-liner, and the files its state lists.',
1182
1183
  projections: {
1183
1184
  [String(KIND_CHANNEL_METADATA)]: {
1184
1185
  widget: 'card',
1185
- noun: 'folder',
1186
+ noun: 'team',
1186
1187
  // The cut Peek's claim made, so no card grows when the claim goes.
1187
1188
  slots: { title: { tag: 'name' }, subtitle: { tag: 'about', truncate: 120 } },
1188
1189
  },
@@ -2070,14 +2071,14 @@ export function actionProblems(declared) {
2070
2071
  const creates = input?.type === 'object' && !!properties;
2071
2072
  if (emits?.placement !== undefined && !(creates && PLACEMENTS.includes(emits.placement))) {
2072
2073
  problems.push(creates
2073
- ? `${name} places its object with ${JSON.stringify(emits.placement)}, and a Folder is named by ${PLACEMENTS.join(' or ')} — a consumer refuses the action.`
2074
- : `${name} declares a placement and creates nothing; only a new root names its Folder, so it is ignored.`);
2074
+ ? `${name} places its object with ${JSON.stringify(emits.placement)}, and a team is named by ${PLACEMENTS.join(' or ')} — a consumer refuses the action.`
2075
+ : `${name} declares a placement and creates nothing; only a new root names its team, so it is ignored.`);
2075
2076
  }
2076
2077
  if (emits?.listed !== undefined && emits.listed !== true) {
2077
2078
  problems.push(`${name} declares listed ${JSON.stringify(emits.listed)}; the only value is true.`);
2078
2079
  }
2079
2080
  else if (emits?.listed === true && !creates && emits.kind !== KIND_DELETION) {
2080
- problems.push(`${name} declares listed on an action that neither creates nor deletes, so no Folder command follows it.`);
2081
+ problems.push(`${name} declares listed on an action that neither creates nor deletes, so no team command follows it.`);
2081
2082
  }
2082
2083
  const formats = [
2083
2084
  // A scalar format means something on a change only: a comment's body is
@@ -2790,7 +2791,12 @@ manifestFor) {
2790
2791
  * in a Folder they cannot read never comes back. A failed read rejects.
2791
2792
  */
2792
2793
  export async function resolveForeignRoots(references, query, cache,
2793
- /** `archivedWith` marks a file archived with an archived parent, as {@link resolveForeignObject}'s does (SHIPS-2). */
2794
+ /**
2795
+ * `archivedWith` marks a file archived with an archived parent, as {@link resolveForeignObject}'s does (SHIPS-2).
2796
+ * `listRead`, where the relay offers the list read (NIP-11 `file_list`), reads each file of the relay's file kinds
2797
+ * as its first record and its fields' current changes (§6.13), not every change ever made to it: no text, and a
2798
+ * deleted file is absent. Other kinds are read as before.
2799
+ */
2794
2800
  options = {}) {
2795
2801
  const pointers = new Map();
2796
2802
  for (const reference of references) {
@@ -2800,27 +2806,37 @@ options = {}) {
2800
2806
  }
2801
2807
  if (pointers.size === 0)
2802
2808
  return [];
2803
- const manifests = new Map();
2804
- const byApp = new Map();
2805
- for (const pointer of pointers.values())
2806
- byApp.set(manifestKeyOf(pointer), pointer);
2807
- await Promise.all([...byApp].map(async ([key, pointer]) => {
2808
- const resolved = await resolveManifest(pointer, query, cache);
2809
- if (resolved)
2810
- manifests.set(key, resolved);
2811
- }));
2809
+ const manifests = await manifestsOf(pointers.values(), query, cache);
2812
2810
  const filters = [];
2811
+ // One list read per author and kind: `limit` counts first records there, not the changes beside them.
2812
+ const listedBy = new Map();
2813
2813
  for (const [address, pointer] of pointers) {
2814
2814
  const resolved = manifests.get(manifestKeyOf(pointer));
2815
2815
  if (!resolved?.manifest.projections?.[String(pointer.kind)])
2816
2816
  continue;
2817
+ if (options.listRead && FILE_KINDS.includes(pointer.kind)) {
2818
+ const key = `${pointer.kind}:${pointer.pubkey}`;
2819
+ const group = listedBy.get(key) ?? { kind: pointer.kind, pubkey: pointer.pubkey, identifiers: [] };
2820
+ group.identifiers.push(pointer.identifier);
2821
+ listedBy.set(key, group);
2822
+ continue;
2823
+ }
2824
+ const root = { kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 };
2817
2825
  // A manifest without `records` folds by a placeholder kind 0, never sent.
2818
2826
  const changeKinds = new Set([foldRuleOf(resolved.manifest).changeKind, archiveRuleOf(resolved.manifest).changeKind].filter((k) => k !== 0));
2819
- filters.push({ kinds: [pointer.kind], authors: [pointer.pubkey], '#d': [pointer.identifier], limit: 1 }, { kinds: [...changeKinds], '#a': [address], limit: 500 });
2827
+ filters.push(root, { kinds: [...changeKinds], '#a': [address], limit: 500 });
2820
2828
  }
2821
- if (filters.length === 0)
2829
+ const listed = [];
2830
+ for (const { kind, pubkey, identifiers } of listedBy.values()) {
2831
+ for (let start = 0; start < identifiers.length; start += RELAY_PAGE_CEILING) {
2832
+ const chunk = identifiers.slice(start, start + RELAY_PAGE_CEILING);
2833
+ listed.push({ kinds: [kind], authors: [pubkey], '#d': chunk, limit: chunk.length, fields: 'newest' });
2834
+ }
2835
+ }
2836
+ if (filters.length === 0 && listed.length === 0)
2822
2837
  return [];
2823
- const events = await queryChunked(filters, query);
2838
+ // A relay refuses a request mixing list reads with plain ones, so each goes on its own.
2839
+ const events = (await Promise.all([queryChunked(filters, query), queryChunked(listed, query)])).flat();
2824
2840
  const objects = projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer)));
2825
2841
  if (options.archivedWith) {
2826
2842
  const manifestOf = (object) => {
@@ -2831,6 +2847,37 @@ options = {}) {
2831
2847
  }
2832
2848
  return objects;
2833
2849
  }
2850
+ /** The manifest each pointer's author reads it through, one read per `kind:pubkey`. */
2851
+ async function manifestsOf(pointers, query, cache) {
2852
+ const manifests = new Map();
2853
+ const byApp = new Map();
2854
+ for (const pointer of pointers)
2855
+ byApp.set(manifestKeyOf(pointer), pointer);
2856
+ await Promise.all([...byApp].map(async ([key, pointer]) => {
2857
+ const resolved = await resolveManifest(pointer, query, cache);
2858
+ if (resolved)
2859
+ manifests.set(key, resolved);
2860
+ }));
2861
+ return manifests;
2862
+ }
2863
+ /**
2864
+ * The files a list read answered (§6.13) — each first record with its fields'
2865
+ * current changes — folded through their apps' manifests as
2866
+ * {@link resolveForeignRoots} folds them. Nothing more is read but the manifests.
2867
+ */
2868
+ export async function projectListedFiles(events, query, cache) {
2869
+ const pointers = [];
2870
+ for (const event of events) {
2871
+ // A change names its file by `a` and carries no `d`.
2872
+ const identifier = tagValue(event, 'd');
2873
+ if (identifier !== undefined)
2874
+ pointers.push({ kind: event.kind, pubkey: event.pubkey, identifier, relays: [] });
2875
+ }
2876
+ if (pointers.length === 0)
2877
+ return [];
2878
+ const manifests = await manifestsOf(pointers, query, cache);
2879
+ return projectEvents(events, (pointer) => manifests.get(manifestKeyOf(pointer)));
2880
+ }
2834
2881
  /**
2835
2882
  * The parent each file sits under, and nothing else — FOL-50.
2836
2883
  *
@@ -4430,7 +4477,7 @@ function buildCreationEvent(args) {
4430
4477
  const bodyField = bodyFields[0];
4431
4478
  const placement = declared.emits.placement ?? 'h';
4432
4479
  if (!PLACEMENTS.includes(placement)) {
4433
- return `"${declared.label}" places its object with "${placement}", and a Folder is named by ${PLACEMENTS.join(' or ')}.`;
4480
+ return `"${declared.label}" places its object with "${placement}", and a team is named by ${PLACEMENTS.join(' or ')}.`;
4434
4481
  }
4435
4482
  // Only the content field can be prose, so only its value is ever tagged.
4436
4483
  const prose = proseTags({
@@ -4495,7 +4542,7 @@ function personKeyProblem(label, value) {
4495
4542
  export function buildActionEvent(args) {
4496
4543
  const declared = args.manifest.actions?.find((a) => a.id === args.actionId);
4497
4544
  if (declared?.emits.listed === true && (declared.emits.kind === KIND_DELETION || isCreationAction(declared))) {
4498
- return `"${declared.label}" is followed by a Folder command, so it is built with buildActionEvents.`;
4545
+ return `"${declared.label}" is followed by a team command, so it is built with buildActionEvents.`;
4499
4546
  }
4500
4547
  return buildOneActionEvent(args);
4501
4548
  }
@@ -4528,7 +4575,7 @@ export function buildActionEvents(args) {
4528
4575
  return [first];
4529
4576
  if (declared.emits.kind === KIND_DELETION) {
4530
4577
  if (!args.listedIn)
4531
- return `"${declared.label}" unlists what it deletes, and needs the Folders that list it.`;
4578
+ return `"${declared.label}" unlists what it deletes, and needs the teams that list it.`;
4532
4579
  // One remove per Folder, however many reads it came back from.
4533
4580
  const folders = [...new Map(args.listedIn.map((listing) => [listing.id, listing])).values()];
4534
4581
  return [
@@ -4538,7 +4585,7 @@ export function buildActionEvents(args) {
4538
4585
  }
4539
4586
  if (isCreationAction(declared)) {
4540
4587
  if (args.folderHasState === undefined) {
4541
- return `"${declared.label}" lists what it creates, and needs to know whether the Folder has state.`;
4588
+ return `"${declared.label}" lists what it creates, and needs to know whether the team has state.`;
4542
4589
  }
4543
4590
  // A listing names addresses, and an object with no `d` has none.
4544
4591
  const identifier = first.tags.find((t) => t[0] === 'd')?.[1];