TBD54566975 / dwn-sdk-js

Decentralized Web Node (DWN) Reference implementation

Home Page:https://identity.foundation/decentralized-web-node/spec/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apply consistency to `dateCreated` and `dateModified` across all DWN interfaces

thehenrytsai opened this issue · comments

Currently, dateCreated means date "record" created in Record interface, but mean date "message" created in others. dateModified always means date "message" created, but is used only in Record and Protocol interface - basically it's kind of a mess... = ]

There a number of proposals to fix this inconsistency, first we have this:

  1. Require all DWN message to have messageTimestamp
  2. dateCreated is a method specific property, ie. in RecordsWrite.
  3. Remove/rename all other variant of date related properties accordingly.
export type RecordsWriteDescriptor = {
  interface: 'Records';
  method: 'Write';
  messageTimestamp: string;
  dateCreated: string;
  datePublished?: string;
  ...
};

export type RecordsQueryDescriptor = {
  interface: 'Records';
  method: 'Query';
  messageTimestamp: string;
  filter: RecordsQueryFilter;
  dateSort?: DateSort;
};

export type RecordsReadDescriptor = {
  interface: 'Records';
  method: 'Read';
  messageTimestamp: string;
  recordId: string;
};

export type RecordsDeleteDescriptor = {
  interface: 'Records';
  method: 'Delete';
  messageTimestamp: string;
  recordId: string;
};

export type ProtocolsConfigureDescriptor = {
  interface : 'Protocols';
  method: 'Configure';
  messageTimestamp: string;
  dateCreated: string; // assuming we want/need it at some point
  definition: ProtocolDefinition;
};

export type ProtocolsQueryDescriptor = {
  interface : 'Protocols',
  method: 'Query';
  messageTimestamp: string;
  filter?: ProtocolsQueryFilter
};

export type PermissionsRequestDescriptor = {
  interface: 'Permissions';
  method: 'Request';
  messageTimestamp: string;
  ...
};

export type PermissionsGrantDescriptor = {
  interface: 'Permissions';
  method: 'Grant';
  messageTimestamp: string;
  ...
};

export type SnapshotsCreateDescriptor = {
  interface : 'Snapshots';
  method: 'Create';
  messageTimestamp: string;
  definitionCid: string;
};

It might be worth entertaining the idea of taking the messageTimestamp out of the descriptor container.

Keeping the above semantic meaning exactly the same, an alternate naming scheme was also proposed:

  1. But this would introduce a bunch of special dateXYZCreated property that is arguably ugly and unnecessary.
export type RecordsWriteDescriptor = {
  interface: 'Records';
  method: 'Write';
  dateCreated: string;
  dateRecordCreated: string;
  dateRecordPublished?: string;
  ...
};

export type RecordsQueryDescriptor = {
  interface: 'Records';
  method: 'Query';
  dateCreated: string;
  filter: RecordsQueryFilter;
  dateSort?: DateSort;
};

export type RecordsReadDescriptor = {
  interface: 'Records';
  method: 'Read';
  dateCreated: string;
  recordId: string;
};

export type RecordsDeleteDescriptor = {
  interface: 'Records';
  method: 'Delete';
  dateCreated: string;
  recordId: string;
};

export type ProtocolsConfigureDescriptor = {
  interface : 'Protocols';
  method: 'Configure';
  dateCreated: string;
  dateProtocolCreated: string; // assuming we want/need it at some point
  definition: ProtocolDefinition;
};

export type ProtocolsQueryDescriptor = {
  interface : 'Protocols',
  method: 'Query';
  dateCreated: string;
  filter?: ProtocolsQueryFilter
};

export type PermissionsRequestDescriptor = {
  interface: 'Permissions';
  method: 'Request';
  dateCreated: string;
  ...
};

export type PermissionsGrantDescriptor = {
  interface: 'Permissions';
  method: 'Grant';
  dateCreated: string;
  ...
};

export type SnapshotsCreateDescriptor = {
  interface : 'Snapshots';
  method: 'Create';
  dateCreated: string;
  definitionCid: string;
};

Finally we have the proposal that does not have a dedicated property for the message timestamp:

  1. Presence of dateModified would imply that's the message timestamp, absence of dateModified would imply that dateCreated is the message timestamp. You can't compare the age of two messages by looking at the same property for all message types, so we'll have to remove existing "generic age comparison" methods from the base Message class.
  2. It is arguably better/worse functionally/logically, but objectively nicer to the eye at very least.
export type RecordsWriteDescriptor = {
  interface: 'Records';
  method: 'Write';
  dateCreated: string;
  dateModified: string;
  datePublished?: string;
  ...
};

export type RecordsQueryDescriptor = {
  interface: 'Records';
  method: 'Query';
  dateCreated: string;
  filter: RecordsQueryFilter;
  dateSort?: DateSort;
};

export type RecordsReadDescriptor = {
  interface: 'Records';
  method: 'Read';
  dateCreated: string;
  recordId: string;
};

export type RecordsDeleteDescriptor = {
  interface: 'Records';
  method: 'Delete';
  dateCreated: string;
  recordId: string;
};

export type ProtocolsConfigureDescriptor = {
  interface : 'Protocols';
  method: 'Configure';
  dateCreated: string; // assuming we want/need it at some point
  dateModified: string;
  definition: ProtocolDefinition;
};

export type ProtocolsQueryDescriptor = {
  interface : 'Protocols',
  method: 'Query';
  dateCreated: string;
  filter?: ProtocolsQueryFilter
};

export type PermissionsRequestDescriptor = {
  interface: 'Permissions';
  method: 'Request';
  dateCreated: string;
  ...
};

export type PermissionsGrantDescriptor = {
  interface: 'Permissions';
  method: 'Grant';
  dateCreated: string;
  ...
};

export type SnapshotsCreateDescriptor = {
  interface : 'Snapshots';
  method: 'Create';
  dateCreated: string;
  definitionCid: string;
};

Based on the prior discussions, the approach that has the most support amongst the group and fewest negative impacts is:

Require all DWN message to have messageTimestamp
dateCreated is a method specific property, ie. in RecordsWrite.
Remove/rename all other variant of date related properties accordingly.

👍 on proceeding with the change in dwn-sdk-js ƒrom my end.

From a logical perspective, I continue to believe that when we surface objects, like Records, to developers in Web5.js that we refer to the timestamp of initial creation as dateCreated and the most recent modification timestamp as dateModified. A property called messageTimestamp will not intuitively make sense if there is no awareness of messages or message stores.

#419 addressed this