Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions packages/ceramic-cli/src/bin/ceramic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ program
.command('create <doctype>')
.option('--content <content>', 'New document content')
.option('--only-genesis', 'Only create the genesis object. No anchor will be created')
.option('--owners <owners>', 'Specify a comma-separated list of the owners of the document. Defaults to current user')
.option('--controllers <controllers>', 'Specify a comma-separated list of the controllers of the document. Controllers are the users that are allowed to publish updates to this document. Defaults to current user')
.option('--unique', 'Ensure document is unique regardless of content')
.option('--schema <schema>', 'Schema document ID')
.description('Create a new document')
.action(async (doctype, { content, onlyGenesis, owners, unique, schema }) => {
await CeramicCliUtils.createDoc(doctype, content, owners, onlyGenesis, unique, schema)
.action(async (doctype, { content, onlyGenesis, controllers, unique, schema }) => {
await CeramicCliUtils.createDoc(doctype, content, controllers, onlyGenesis, unique, schema)
})

program
.command('change <docId>')
.option('--content <content>', 'Change document content')
.option('--owners <owners>', 'Change owner of this document (only 3ID)')
.option('--controllers <controllers>', 'Change controllers of this document (only 3ID)')
.option('--schema <schema>', 'Change the schema document ID')
.description('Update the content of a document')
.action(async (docId, { content, owners, schema }) => {
await CeramicCliUtils.change(docId, content, owners, schema)
.action(async (docId, { content, controllers, schema }) => {
await CeramicCliUtils.change(docId, content, controllers, schema)
})

program
Expand Down Expand Up @@ -76,19 +76,19 @@ schemas.description('Ceramic schemas')
schemas
.command('create <new-content>')
.option('--only-genesis', 'Only create the genesis object. No anchor will be created')
.option('--owners <owners>', 'Specify a comma-separated list of the owners of the schema document. Defaults to' + ' current user')
.option('--controllers <controllers>', 'Specify a comma-separated list of the controllers of the schema document. Defaults to' + ' current user')
.option('--unique', 'Ensure schema document is unique regardless of content')
.description('Create a new schema')
.action(async (content, { onlyGenesis, owners, unique }) => {
await CeramicCliUtils.schemaCreateDoc(content, owners, onlyGenesis, unique)
.action(async (content, { onlyGenesis, controllers, unique }) => {
await CeramicCliUtils.schemaCreateDoc(content, controllers, onlyGenesis, unique)
})

schemas
.command('change <docId> <new-content>')
.option('--owners <owners>', 'Change owner of this document (only 3ID)')
.option('--controllers <controllers>', 'Change controllers of this document (only 3ID)')
.description('Update the content of a schema')
.action(async (docId, content, { owners }) => {
await CeramicCliUtils.schemaChangeDoc(docId, content, owners)
.action(async (docId, content, { controllers }) => {
await CeramicCliUtils.schemaChangeDoc(docId, content, controllers)
})

const pin = program.command('pin')
Expand Down
38 changes: 19 additions & 19 deletions packages/ceramic-cli/src/ceramic-cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ export class CeramicCliUtils {
* Create document
* @param doctype - Document type
* @param content - Document content
* @param owners - Document owners
* @param controllers - Document controllers
* @param onlyGenesis - Create only a genesis record (no publish or anchor)
* @param isUnique - Should document be unique?
* @param schemaDocId - Schema document ID
*/
static async createDoc(doctype: string, content: string, owners: string, onlyGenesis: boolean, isUnique: boolean, schemaDocId: string = null): Promise<void> {
static async createDoc(doctype: string, content: string, controllers: string, onlyGenesis: boolean, isUnique: boolean, schemaDocId: string = null): Promise<void> {
await CeramicCliUtils._runWithCeramic(async (ceramic: CeramicClient) => {
const parsedOwners = CeramicCliUtils._parseOwners(owners)
const parsedControllers = CeramicCliUtils._parseControllers(controllers)
const parsedContent = CeramicCliUtils._parseContent(content)

const params = {
content: parsedContent, metadata: {
owners: parsedOwners, isUnique, schema: schemaDocId
controllers: parsedControllers, isUnique, schema: schemaDocId
}
}

Expand All @@ -118,10 +118,10 @@ export class CeramicCliUtils {
* Change document
* @param docId - Document ID
* @param content - Document content
* @param owners - Document owners
* @param controllers - Document controllers
* @param schemaDocId - Optional schema document ID
*/
static async change(docId: string, content: string, owners: string, schemaDocId?: string): Promise<void> {
static async change(docId: string, content: string, controllers: string, schemaDocId?: string): Promise<void> {
const id = DocID.fromString(docId)

const version = id.version
Expand All @@ -131,13 +131,13 @@ export class CeramicCliUtils {
}

await CeramicCliUtils._runWithCeramic(async (ceramic: CeramicClient) => {
const parsedOwners = CeramicCliUtils._parseOwners(owners)
const parsedControllers = CeramicCliUtils._parseControllers(controllers)
const parsedContent = CeramicCliUtils._parseContent(content)

const doc = await ceramic.loadDocument(id)
await doc.change({
content: parsedContent, metadata: {
owners: parsedOwners, schema: schemaDocId
controllers: parsedControllers, schema: schemaDocId
}
})

Expand Down Expand Up @@ -204,25 +204,25 @@ export class CeramicCliUtils {
/**
* Create schema document
* @param content - Schema content
* @param owners - Schema owners
* @param controllers - Schema controllers
* @param onlyGenesis - Create only a genesis record (no publish or anchor)
* @param isUnique - Should document be unique?
*/
static async schemaCreateDoc(content: string, owners: string, onlyGenesis: boolean, isUnique: boolean): Promise<void> {
static async schemaCreateDoc(content: string, controllers: string, onlyGenesis: boolean, isUnique: boolean): Promise<void> {
// TODO validate schema on the client side
return CeramicCliUtils.createDoc('tile', content, owners, onlyGenesis, isUnique)
return CeramicCliUtils.createDoc('tile', content, controllers, onlyGenesis, isUnique)
}

/**
* Change schema document
* @param schemaDocId - Schema document ID
* @param content - Schema document content
* @param owners - Schema document owners
* @param controllers - Schema document controllers
*/
static async schemaChangeDoc(schemaDocId: string, content: string, owners: string): Promise<void> {
static async schemaChangeDoc(schemaDocId: string, content: string, controllers: string): Promise<void> {
DocID.fromString(schemaDocId)
// TODO validate schema on the client side
return CeramicCliUtils.change(schemaDocId, content, owners, null)
return CeramicCliUtils.change(schemaDocId, content, controllers, null)
}

/**
Expand Down Expand Up @@ -396,14 +396,14 @@ export class CeramicCliUtils {
}

/**
* Parse input owners
* @param owners - Input owners
* Parse input controllers
* @param controllers - Input controllers
* @private
*/
static _parseOwners(owners: string): string[] {
if (owners == null) {
static _parseControllers(controllers: string): string[] {
if (controllers == null) {
return [ ]
}
return owners.includes(',') ? owners.split(',') : [owners]
return controllers.includes(',') ? controllers.split(',') : [controllers]
}
}
8 changes: 4 additions & 4 deletions packages/ceramic-common/src/doctype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface AnchorProof {
* Document metadata
*/
export interface DocMetadata {
owners: Array<string>;
controllers: Array<string>;
schema?: string;
tags?: Array<string>;
isUnique?: boolean;
Expand All @@ -64,7 +64,7 @@ export interface DocParams {
*/
export interface DocNext {
content?: any;
owners?: Array<string>;
controllers?: Array<string>;
metadata?: DocMetadata;
}

Expand Down Expand Up @@ -117,8 +117,8 @@ export abstract class Doctype extends EventEmitter {
return cloneDeep(next?.metadata ?? metadata)
}

get owners(): Array<string> {
return this.metadata.owners
get controllers(): Array<string> {
return this.metadata.controllers
}

get head(): CID {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Doctype', () => {
const docSchemaState = mock<DocState>()
docSchemaState.content = schema
docSchemaState.metadata = {
owners: [],
controllers: [],
schema: 'ceramic://1234567'
}

Expand All @@ -40,7 +40,7 @@ describe('Doctype', () => {
it('should pass schema validation', async () => {
const state = mock<DocState>()
state.metadata = {
owners: [],
controllers: [],
schema: 'ceramic://1234567'
}
state.content = {
Expand All @@ -54,7 +54,7 @@ describe('Doctype', () => {
it('should fail schema validation', async () => {
const state = mock<DocState>()
state.metadata = {
owners: [],
controllers: [],
schema: 'ceramic://1234567'
}
state.content = {
Expand Down
Loading