Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 210 additions & 1 deletion typescript-types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,219 @@
* LICENSE: MIT
*/

export type Author = Record<string, unknown> & {};
/** =====================
* Common Primitive Aliases
* ===================== */

export type URI = string; // in JSON schema this should be a validated string

/**
* An item which allows flexible and descriptive values.
*/
export interface PropertyValue {
type: "PropertyValue";

propertyId: string;

value: any;
}

/** =====================
* MediaObject
* ===================== */
export type MediaObject = Record<string, unknown> & {
type: "MediaObject"

/** Actual bytes of the media object, e.g., the image or video file. */
contentUri: URI;
}

/** =====================
* Organization
* ===================== */
export type Organization = Record<string, unknown> & {
type: "Organization"

/** Physical address of the item. */
address?: PostalAddress;

/** The URI(s) associated with this organization. */
uris?: URI[]

/** The name of the organization. */
name: string;

/** Contact emails. */
emails?: string[]; // In JSON-schema this should be of format "email".

/** Identifiers for the organization. */
identifiers: PropertyValue[];

/** Parent organizations (supersedes branchOf). */
parentOrganizations?: Organization[];

/** An Organization to which this Organization belongs. */
memberOf?: Organization[];

/** Members (Persons or Organizations). */
members?: (Person | Organization)[];

/** Sub-organizations (inverse of parentOrganizations). */
subOrganization?: Organization[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need subOrganizations here; if they were involved, then they should be the actual organization in the attribution. If not, then they shouldn't appear at all. I don't think this adds information that's necessary for a document to be completely described.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also includes departments for an institute which may have different identifiers and billing contracts. I was going off of how Stencila uses this portion.

}

/** =====================
* Author and AuthorCRediT
* ===================== */
export type Author = Record<string, unknown> & {
type: "Author"

/** The creator of an item. */
author: Organization | Person;

/** Description of how a user contributed. */
contributorRoles: (PropertyValue | AuthorCRediT)[];

/** Order of appearance (tie-break by family name). */
order?: number; // In JSON-schema this should have a minimum of 0.
}

export enum AuthorCRediT {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid typescript enums; they have negative downstream consequences for building packages. See eg https://www.totaltypescript.com/why-i-dont-like-typescript-enums

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Good point. How should we handle this? They are supported in JSON-schema.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even want to support AuthCredit or should we just leave it as PropertyValue like other identifiers?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string[]?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PropertyValue makes you have to see what kind of identifier it is in case it changes what things people want to use for contributions. Makes it a longer lasting schema.

Conceptualization = "Conceptualization",
Methodology = "Methodology",
Software = "Software",
Validation = "Validation",
FormalAnalysis = "Formal analysis",
Investigation = "Investigation",
Resources = "Resources",
DataCuration = "Data Curation",
WritingOriginalDraft = "Writing - Original Draft",
WritingReviewEditing = "Writing - Review & Editing",
Visualization = "Visualization",
Supervision = "Supervision",
ProjectAdministration = "Project administration",
FundingAcquisition = "Funding acquisition",
}

/** =====================
* Person
* ===================== */
export type Person = Record<string, unknown> & {
type: "Person"

/** Identifiers for a person. */
identifiers?: PropertyValue[];

/** Affiliations. */
affiliations?: Affiliation[];

/** Emails. */
emails?: string[]; // In JSON-schema this should have a format of email.

/** Names the author is known by. */
names: PersonName[];

/** Physical address. */
address?: PostalAddress;
}

/**
* The affiliation between people and organziations.
*/
export type Affiliation = Record<string, unknown> & {
type: "Affiliation"

/** The Organization or Person itself. */
affiliate: Organization | Person;

/** The date the affiliation to this item began. */
dateStart?: string; // in JSON-schema this should be format date or date-time

/** The date the affiliation to this item ended. Leave blank to indicate the affiliation is current. */
dateEnd?: string; // in JSON-schema this should be format date or date-time

/** Describe the relationship to the item. */
affiliationType: string; // in JSON-schema this should have the description, "Describe the relationship to the item."
}

/**
* The name of a Person object.
*/
export type PersonName = Record<string, unknown> & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that article! I was talking to Nokome about how I'm, myself, an edgecase with multiple legal names. So! I'm going off of schema.org and Stencila here as a compromise. I think this is the best and most common way of gathering this information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made family name optional in latest push.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm, in this case, not letting "good" get in the way of "good enough". :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In schema.org they're all optional and a single string: https://schema.org/Person

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Stencila has multiple/array here which is where I based off of. I originally had it as a single value, but Nokome pointed out Stencila has needed to use multiple values for names so that seems fine to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nokome, tagging you here for comment: can you give a bit more context on how multiple names are used, in contrast to how CSL-JSON does it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: "PersonName"

/** Family name. In the U.S., the last name of a Person. */
familyNames?: string[];

/** Given name. In the U.S., the first name of a Person. */
givenNames?: string[];

/** An honorific prefix preceding a Person's name such as Dr/Mrs/Mr. */
honorificPrefixes?: string[];

/** An honorific suffix following a Person's name such as M.D./PhD/MSCSW. */
honorificSuffixes?: string[];
}

/** =====================
* Funding information block.
* ===================== */
/**
* The source of funding for a scholarly work.
*/
export type FundingSource = Record<string, unknown> & {
type: "FundingSource"

/** Ways to identify the grant. */
identifiers?: PropertyValue[];

/** The person or organization funding. */
funder: Person | Organization;

/** The monetary or non-monetary contribution. */
funding: MonetaryAmount | Product | Service;

/** Description of what the funding contributed towards. */
description?: string;
}

/**
* The way to connect a funding source to its funded item.
*/
export type Grant = FundingSource & {
type: "Grant";

/**
* Something funded or sponsored through a Grant.
*/
fundedItem: ScholarlyWork | Person | Organization | Event | Product;
}

/** =====================
* MonetaryAmount
* ===================== */
export type MonetaryAmount = Record<string, unknown> & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too fine-grained.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it helps add some structure. We do need to enforce something. Schema.org has these mechanics and I think it's a good way of doing it. There are multiple options.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need to enforce something.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having too much flexibility brings us back to JATS.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about exchanging documents. We truly don't have to define a standard for exchanging monetary units.

type: "MonetaryAmount";

/** Currency, e.g., USD, BTC, etc. */
currency: string;

/** The value of the monetary amount. */
value: number;
}

/** =====================
* Placeholder Types (referenced but not defined in YAML)
* ===================== */


export interface PostalAddress { [key: string]: any; }
export interface ScholarlyWork { [key: string]: any; }
export interface Event { [key: string]: any; }
export interface Product { [key: string]: any; }
export interface Service { [key: string]: any; }


export type License = {
uri?: URI; // link to full version of license if short name provided
name?: string; // short name (eg "CC-BY-SA 3.0", "MIT")
Expand Down