Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbcfd committed Dec 5, 2023
1 parent 16b0ecf commit 2e41e5e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/composite/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class CompositeCompile extends Command<Flags> {
composite = await Composite.fromJSON({ ceramic: this.ceramic, definition })
outputPaths = allArgs
} else if (this.stdin === undefined && allArgs.length >= 2) {
composite = await readEncodedComposite(this.ceramic, allArgs[0])
composite = await readEncodedComposite(this.ceramic, allArgs[0], false)
outputPaths = allArgs.splice(1)
} else if (this.stdin !== undefined && allArgs.length < 1) {
this.spinner.fail(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/composite/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class CreateComposite extends Command<Flags, { schemaFilePath: st
description:
'Deploy the composite to the ceramic node, which will start indexing on the composite',
default: true,
allowNo: true,
}),
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/composite/extract-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class CompositeExtractModel extends Command<Flags> {
composite = await Composite.fromJSON({ ceramic: this.ceramic, definition })
modelsToExtract = allArgs
} else if (this.stdin === undefined && allArgs.length >= 2) {
composite = await readEncodedComposite(this.ceramic, allArgs[0])
composite = await readEncodedComposite(this.ceramic, allArgs[0], false)
modelsToExtract = allArgs.splice(1)
} else if (this.stdin !== undefined && allArgs.length < 1) {
this.spinner.fail(
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/commands/composite/from-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { writeEncodedComposite } from '@composedb/devtools-node'

type Flags = CommandFlags & {
output?: string
deploy: boolean
}

export default class CompositeFromModel extends Command<Flags> {
Expand All @@ -18,6 +19,12 @@ export default class CompositeFromModel extends Command<Flags> {
char: 'o',
description: 'path to the file where the composite representation should be saved',
}),
deploy: Flags.boolean({
char: 'd',
description:
'Deploy the composite to the ceramic node, which will start indexing on the composite',
default: true,
}),
}

async run(): Promise<void> {
Expand All @@ -44,6 +51,7 @@ export default class CompositeFromModel extends Command<Flags> {
const composite = await Composite.fromModels({
ceramic: this.ceramic,
models: allModelStreamIDs,
index: this.flags.deploy,
})
if (this.flags.output != null) {
const output = this.flags.output
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/composite/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class CompositeMerge extends Command<Flags> {
try {
this.spinner.start('Merging composites...')
const composites = await Promise.all(
compositePaths.map(async (path) => await readEncodedComposite(this.ceramic, path)),
compositePaths.map(async (path) => await readEncodedComposite(this.ceramic, path, false)),
)

const commonEmbedsFlag = this.flags['common-embeds'] as string | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/composite/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class CompositeModels extends Command<
const definition = JSON.parse(this.stdin) as EncodedCompositeDefinition
composite = await Composite.fromJSON({ ceramic: this.ceramic, definition })
} else if (this.args.compositePath !== undefined) {
composite = await readEncodedComposite(this.ceramic, this.args.compositePath)
composite = await readEncodedComposite(this.ceramic, this.args.compositePath, false)
} else {
this.spinner.fail(
'You need to pass a path to encoded composite either via an arg or through stdin',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/composites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('composites', () => {
'composite:create',
'test/mocks/composite.profile.post.schema',
`--did-private-key=${seed}`,
`--no-deploy`,
])
const output = create.stdout.toString()
const def = JSON.parse(output) as EncodedCompositeDefinition
Expand Down
10 changes: 5 additions & 5 deletions packages/devtools-node/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function createComposite(
deploy: boolean,
): Promise<Composite> {
const file = await readFile(getFilePath(path))
return await Composite.create({ ceramic, schema: file.toString(), index: !deploy })
return await Composite.create({ ceramic, schema: file.toString(), index: deploy })
}

/**
Expand All @@ -40,12 +40,12 @@ export async function createComposite(
export async function readEncodedComposite(
ceramic: CeramicClient | string,
path: PathInput,
index?: boolean,
deploy: boolean,
): Promise<Composite> {
const client = typeof ceramic === 'string' ? new CeramicClient(ceramic) : ceramic
const file = getFilePath(path)
const definition = (await readJSON(file)) as EncodedCompositeDefinition
return Composite.fromJSON({ ceramic: client, definition: definition, index: index })
return Composite.fromJSON({ ceramic: client, definition: definition, index: deploy })
}

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ export async function writeEncodedCompositeRuntime(
runtimePath: PathInput,
schemaPath?: PathInput,
): Promise<void> {
const definition = await readEncodedComposite(ceramic, definitionPath)
const definition = await readEncodedComposite(ceramic, definitionPath, false)
const runtime = definition.toRuntime()
await writeRuntimeDefinition(runtime, runtimePath)
if (schemaPath != null) {
Expand All @@ -134,7 +134,7 @@ export async function mergeEncodedComposites(
): Promise<string> {
const sources = Array.isArray(source) ? source : [source]
const composites = await Promise.all(
sources.map(async (path) => await readEncodedComposite(ceramic, path)),
sources.map(async (path) => await readEncodedComposite(ceramic, path, false)),
)
const file = getFilePath(destination)
await writeEncodedComposite(Composite.from(composites), file)
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ export async function serveEncodedDefinition(
params: ServeDefinitionParams,
): Promise<GraphQLServer> {
const { path, ...rest } = params
const composite = await readEncodedComposite(params.ceramicURL, path)
const composite = await readEncodedComposite(params.ceramicURL, path, false)
return await serveGraphQL({ ...rest, definition: composite.toRuntime() })
}
2 changes: 1 addition & 1 deletion packages/devtools/src/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export type FromModelsParams = CompositeOptions & {
* Whether to add the Models to the index or not. If `true`, the Ceramic instance must be
* authenticated with an admin DID. Defaults to `false`.
*/
index?: boolean
index: boolean
}

/**
Expand Down
9 changes: 5 additions & 4 deletions website/docs/api/commands/cli.composite.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Create an encoded composite definition from GraphQL [Composite Schema](https://d

You can find a detailed guide on the creation of Composites [here](https://developers.ceramic.network/docs/composedb/guides/data-modeling/composites)

If updating your composite, run this command with `--no-deploy`. Your GraphQL
definition will still be updated, but Ceramic will not attempt to re-index
your composite.
If updating your composite by specifying additional fields to filter on using the `createIndex` directive, run this
command with `--no-deploy`. Your GraphQL definition will still be updated, but Ceramic will not attempt to re-index your
composite. For other updates to your composite, such as adding new models, run with `--deploy`.

```
USAGE
Expand All @@ -61,7 +61,8 @@ OPTIONS
-c, --ceramic-url Ceramic API URL
-k, --did-private-key DID Private Key (you can generate a fresh private key using composedb did:generate-private-key)
-o, --output a path to file where the resulting encoded composite definition should be saved
-d, --deploy Deploy the composite to the ceramic node, which will start indexing on the composite
-d, --deploy Deploy the composite to the ceramic node, which will cause the node to start indexing the
models contained within the composite
--no-deploy Do not deploy the composite to the ceramic node
```

Expand Down

0 comments on commit 2e41e5e

Please sign in to comment.