@estiva-app/interop 0.72.0 → 0.74.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/src/projection.ts CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  imetaTag,
23
23
  parseBlockDocument,
24
24
  } from '@estiva-app/protocol'
25
- import { planPlaceFile, planUnlistFile, type FolderRef } from './folders.js'
25
+ import { identifierOf, planPlaceFile, planUnlistFile, type FolderRef } from './folders.js'
26
26
  /*
27
27
  SPEC §6.4's comment strength and §6.3's ordering are the conversation
28
28
  package's (CON-5): one copy of each rule, read here for a file's `comments`,
@@ -5805,6 +5805,9 @@ function buildCreationEvent(args: {
5805
5805
  */
5806
5806
  const PERSON_KEY = /^[0-9a-f]{64}$/
5807
5807
 
5808
+ /** An event id as the relay reads a `prev`: lower-case hex. */
5809
+ const EVENT_ID = /^[0-9a-f]{64}$/
5810
+
5808
5811
  /** Why `value` is neither `''` nor a person's key, or undefined when it is one. */
5809
5812
  function personKeyProblem(label: string, value: string): string | undefined {
5810
5813
  if (value === '' || PERSON_KEY.test(value)) return undefined
@@ -5879,6 +5882,17 @@ export interface ActionEventArgs {
5879
5882
  * only: a comment's text is its `value`, and a creation has its own body.
5880
5883
  */
5881
5884
  note?: string
5885
+ /**
5886
+ * The change this one follows for its field: the id of that field's current
5887
+ * change as the writer read it, or the file's first record's id for its
5888
+ * first change (SPEC §6.2). A change only. Every writer should send it; a
5889
+ * relay that keeps the type in order refuses a change without it, and one
5890
+ * naming a change that is no longer current with `conflict:`, which
5891
+ * {@link writeChange} answers.
5892
+ *
5893
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-its-fields-each-kept-in-order-by-the-relay.md
5894
+ */
5895
+ prev?: string
5882
5896
  pubkey: string
5883
5897
  createdAtMs: number
5884
5898
  }
@@ -5988,6 +6002,13 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
5988
6002
  if (args.note !== undefined && (isCreation || !declared.emits.field || declared.emits.kind === KIND_DELETION)) {
5989
6003
  return `"${declared.label}" is not a change, so it takes no note.`
5990
6004
  }
6005
+ // Only a change follows another for its field (§6.2).
6006
+ if (args.prev !== undefined && (isCreation || !declared.emits.field || declared.emits.kind === KIND_DELETION)) {
6007
+ return `"${declared.label}" is not a change, so it follows no change.`
6008
+ }
6009
+ if (args.prev !== undefined && !EVENT_ID.test(args.prev)) {
6010
+ return `"${declared.label}" follows ${JSON.stringify(args.prev)}, which is not an event id.`
6011
+ }
5991
6012
 
5992
6013
  // An object-creating action is a different event entirely — a new object
5993
6014
  // rather than a change to one — so it branches before the scalar path.
@@ -6072,9 +6093,13 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
6072
6093
  if (typeof prose === 'string') return prose
6073
6094
  const [formatTag, ...files] = prose
6074
6095
 
6096
+ // The file the change is about, by its id, beside its address (§6.2): the
6097
+ // relay keeps each field in order by it.
6098
+ const fileId = records.targetTag === 'a' ? identifierOf(address) : undefined
6075
6099
  const tags: string[][] = declared.emits.field
6076
6100
  ? [
6077
6101
  [records.targetTag, address],
6102
+ ...(fileId !== undefined ? [['O', fileId]] : []),
6078
6103
  [records.fieldTag, declared.emits.field],
6079
6104
  [records.valueTag, value],
6080
6105
  ['h', folder],
@@ -6114,6 +6139,7 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
6114
6139
  // second would be separated by event id — arbitrarily, and differently
6115
6140
  // depending on which app you asked (FRICTION.md A6).
6116
6141
  if (records.order?.includes('ts')) tags.push(['ts', String(args.createdAtMs)])
6142
+ if (args.prev !== undefined) tags.push(['prev', args.prev])
6117
6143
  tags.push(...files)
6118
6144
  // The person, where the relay indexes them: `value` is not indexed, so
6119
6145
  // without this `#p` never finds the change and §11.8 makes nobody a member.
@@ -6150,6 +6176,12 @@ function buildOneActionEvent(args: ActionEventArgs): UnsignedActionEvent | strin
6150
6176
  if (moved?.field === declared.emits.field && typeof value === 'string' && parentAddress.test(value)) {
6151
6177
  tags.push([MOVED_TO_TAG, value])
6152
6178
  }
6179
+ // What the chosen option means, last (§6.2's `stage`): a status says
6180
+ // whether it is open, started, done or dropped, whichever app reads it.
6181
+ const stage = declared.emits.field && declared.input?.enum
6182
+ ? manifest.vocabularies?.[declared.input.enum]?.find((entry) => entry.value === value)?.stage
6183
+ : undefined
6184
+ if (declared.emits.field && stage && STAGES.has(stage as Stage)) tags.push(['stage', declared.emits.field, stage])
6153
6185
 
6154
6186
  return {
6155
6187
  pubkey: args.pubkey,
@@ -6270,6 +6302,12 @@ export interface FolderSummary {
6270
6302
  * (NIP-29). What `planMoveFile` reads as `FolderRef.private`.
6271
6303
  */
6272
6304
  private?: true
6305
+ /**
6306
+ * Present when the relay marks it the Company team: its `kind:39000`
6307
+ * carries `["company"]` (§3.4). What `planMoveFromFolders` reads as
6308
+ * `FolderRef.company`.
6309
+ */
6310
+ company?: true
6273
6311
  /**
6274
6312
  * Who may rename and archive it: the owners and admins on its relay-signed
6275
6313
  * `kind:39001`. Offer Archive only to them — a reader ignores an archive from
@@ -6501,6 +6539,7 @@ async function readFolderRecords(query: QueryFn): Promise<{ events: SignedEvent[
6501
6539
  const name = nameOf(channel)
6502
6540
  if (name !== undefined) folder.name = name
6503
6541
  if (channel.tags.some((tag) => tag[0] === 'private')) folder.private = true
6542
+ if (channel.tags.some((tag) => tag[0] === 'company')) folder.company = true
6504
6543
  const admins = folderAdminsOf(adminsOf.get(id), channel)
6505
6544
  if (admins.length) folder.admins = admins
6506
6545
  folder.channel = pointerToAddress({ kind: KIND_CHANNEL, pubkey: channel.pubkey, identifier: id, relays: [] })
@@ -6930,6 +6969,7 @@ export async function resolveFolderContents(
6930
6969
  name: nameOf(channel),
6931
6970
  hasState: !!state,
6932
6971
  ...(channel?.tags.some((tag) => tag[0] === 'private') ? { private: true as const } : {}),
6972
+ ...(channel?.tags.some((tag) => tag[0] === 'company') ? { company: true as const } : {}),
6933
6973
  ...(admins.length ? { admins } : {}),
6934
6974
  ...(channelAddress ? { channel: channelAddress } : {}),
6935
6975
  ...(state