kubun 0.2.0 → 0.3.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/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g kubun
20
20
  $ kubun COMMAND
21
21
  running command...
22
22
  $ kubun (--version)
23
- kubun/0.2.0 darwin-arm64 node-v23.7.0
23
+ kubun/0.3.0 darwin-arm64 node-v23.9.0
24
24
  $ kubun --help [COMMAND]
25
25
  USAGE
26
26
  $ kubun COMMAND
@@ -212,7 +212,7 @@ DESCRIPTION
212
212
  Display help for kubun.
213
213
  ```
214
214
 
215
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.24/src/commands/help.ts)_
215
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.27/src/commands/help.ts)_
216
216
 
217
217
  ## `kubun model cluster`
218
218
 
@@ -274,7 +274,7 @@ EXAMPLES
274
274
  $ kubun plugins
275
275
  ```
276
276
 
277
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/index.ts)_
277
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/index.ts)_
278
278
 
279
279
  ## `kubun plugins add PLUGIN`
280
280
 
@@ -348,7 +348,7 @@ EXAMPLES
348
348
  $ kubun plugins inspect myplugin
349
349
  ```
350
350
 
351
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/inspect.ts)_
351
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/inspect.ts)_
352
352
 
353
353
  ## `kubun plugins install PLUGIN`
354
354
 
@@ -397,7 +397,7 @@ EXAMPLES
397
397
  $ kubun plugins install someuser/someplugin
398
398
  ```
399
399
 
400
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/install.ts)_
400
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/install.ts)_
401
401
 
402
402
  ## `kubun plugins link PATH`
403
403
 
@@ -428,7 +428,7 @@ EXAMPLES
428
428
  $ kubun plugins link myplugin
429
429
  ```
430
430
 
431
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/link.ts)_
431
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/link.ts)_
432
432
 
433
433
  ## `kubun plugins remove [PLUGIN]`
434
434
 
@@ -469,7 +469,7 @@ FLAGS
469
469
  --reinstall Reinstall all plugins after uninstalling.
470
470
  ```
471
471
 
472
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/reset.ts)_
472
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/reset.ts)_
473
473
 
474
474
  ## `kubun plugins uninstall [PLUGIN]`
475
475
 
@@ -497,7 +497,7 @@ EXAMPLES
497
497
  $ kubun plugins uninstall myplugin
498
498
  ```
499
499
 
500
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/uninstall.ts)_
500
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/uninstall.ts)_
501
501
 
502
502
  ## `kubun plugins unlink [PLUGIN]`
503
503
 
@@ -541,7 +541,7 @@ DESCRIPTION
541
541
  Update installed plugins.
542
542
  ```
543
543
 
544
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.30/src/commands/plugins/update.ts)_
544
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
545
545
 
546
546
  ## `kubun serve`
547
547
 
package/dist/account.js CHANGED
@@ -1,5 +1,5 @@
1
- import { fromB64 } from '@enkaku/codec';
2
- import { getTokenSigner as signerFromKey } from '@enkaku/token';
1
+ import { fromB64 } from '@enkaku/codec'
2
+ import { getTokenSigner as signerFromKey } from '@enkaku/token'
3
3
  export function getSigner(key) {
4
- return signerFromKey(fromB64(key));
4
+ return signerFromKey(fromB64(key))
5
5
  }
package/dist/client.js CHANGED
@@ -1,5 +1,5 @@
1
- import { HTTPClient } from '@kubun/http-client';
2
- import { getSigner } from './account.js';
1
+ import { HTTPClient } from '@kubun/http-client'
2
+ import { getSigner } from './account.js'
3
3
  export function createClient(signerKey, url = 'http://localhost:4321') {
4
- return new HTTPClient({ signer: getSigner(signerKey), url });
4
+ return new HTTPClient({ signer: getSigner(signerKey), url })
5
5
  }
@@ -1,10 +1,10 @@
1
- import { toB64 } from '@enkaku/codec';
2
- import { randomPrivateKey } from '@enkaku/token';
3
- import { Command } from '@oclif/core';
1
+ import { toB64 } from '@enkaku/codec'
2
+ import { randomPrivateKey } from '@enkaku/token'
3
+ import { Command } from '@oclif/core'
4
4
  export default class GenerateAccount extends Command {
5
- static description = 'Generate a random private key to use as account signer';
6
- async run() {
7
- const key = await randomPrivateKey();
8
- this.log(toB64(key));
9
- }
5
+ static description = 'Generate a random private key to use as account signer'
6
+ async run() {
7
+ const key = await randomPrivateKey()
8
+ this.log(toB64(key))
9
+ }
10
10
  }
@@ -1,18 +1,18 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { getSigner } from '../../account.js';
1
+ import { Command, Flags } from '@oclif/core'
2
+ import { getSigner } from '../../account.js'
3
3
  export default class AccountID extends Command {
4
- static description = 'Display the DID of an account given its private key';
5
- static flags = {
6
- privateKey: Flags.string({
7
- description: 'base64-encoded private key',
8
- char: 'k',
9
- env: 'KUBUN_PRIVATE_KEY',
10
- required: true,
11
- }),
12
- };
13
- async run() {
14
- const { flags } = await this.parse(AccountID);
15
- const signer = getSigner(flags.privateKey);
16
- this.log(signer.id);
17
- }
4
+ static description = 'Display the DID of an account given its private key'
5
+ static flags = {
6
+ privateKey: Flags.string({
7
+ description: 'base64-encoded private key',
8
+ char: 'k',
9
+ env: 'KUBUN_PRIVATE_KEY',
10
+ required: true,
11
+ }),
12
+ }
13
+ async run() {
14
+ const { flags } = await this.parse(AccountID)
15
+ const signer = getSigner(flags.privateKey)
16
+ this.log(signer.id)
17
+ }
18
18
  }
@@ -1,32 +1,32 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import ora from 'ora';
3
- import { createClient } from '../../client.js';
4
- import { readJSON } from '../../fs.js';
1
+ import { Command, Flags } from '@oclif/core'
2
+ import ora from 'ora'
3
+ import { createClient } from '../../client.js'
4
+ import { readJSON } from '../../fs.js'
5
5
  export default class DeployGraph extends Command {
6
- static description = 'Deploy a documents model graph';
7
- static flags = {
8
- cluster: Flags.string({
9
- description: 'path of the JSON file of the cluster',
10
- char: 'c',
11
- required: true,
12
- multiple: true,
13
- }),
14
- id: Flags.string({ description: 'graph ID' }),
15
- name: Flags.string({ description: 'graph name', char: 'n' }),
16
- privateKey: Flags.string({
17
- description: 'base64-encoded private key',
18
- char: 'k',
19
- env: 'KUBUN_PRIVATE_KEY',
20
- required: true,
21
- }),
22
- url: Flags.string({ description: 'Kubun server URL' }),
23
- };
24
- async run() {
25
- const spinner = ora('Deploying graph clusters...').start();
26
- const { flags } = await this.parse(DeployGraph);
27
- const client = createClient(flags.privateKey, flags.url);
28
- const clusters = await Promise.all(flags.cluster.map((path) => readJSON(path)));
29
- const graph = await client.deployGraph({ clusters, id: flags.id, name: flags.name });
30
- spinner.succeed(`Deployed graph with ID: ${graph.id}`);
31
- }
6
+ static description = 'Deploy a documents model graph'
7
+ static flags = {
8
+ cluster: Flags.string({
9
+ description: 'path of the JSON file of the cluster',
10
+ char: 'c',
11
+ required: true,
12
+ multiple: true,
13
+ }),
14
+ id: Flags.string({ description: 'graph ID' }),
15
+ name: Flags.string({ description: 'graph name', char: 'n' }),
16
+ privateKey: Flags.string({
17
+ description: 'base64-encoded private key',
18
+ char: 'k',
19
+ env: 'KUBUN_PRIVATE_KEY',
20
+ required: true,
21
+ }),
22
+ url: Flags.string({ description: 'Kubun server URL' }),
23
+ }
24
+ async run() {
25
+ const spinner = ora('Deploying graph clusters...').start()
26
+ const { flags } = await this.parse(DeployGraph)
27
+ const client = createClient(flags.privateKey, flags.url)
28
+ const clusters = await Promise.all(flags.cluster.map((path) => readJSON(path)))
29
+ const graph = await client.deployGraph({ clusters, id: flags.id, name: flags.name })
30
+ spinner.succeed(`Deployed graph with ID: ${graph.id}`)
31
+ }
32
32
  }
@@ -1,32 +1,32 @@
1
- import { Args, Command, Flags } from '@oclif/core';
2
- import ora from 'ora';
3
- import { createClient } from '../../client.js';
1
+ import { Args, Command, Flags } from '@oclif/core'
2
+ import ora from 'ora'
3
+ import { createClient } from '../../client.js'
4
4
  export default class MutateGraph extends Command {
5
- static description = 'Execute a GraphQL mutation on a graph';
6
- static args = {
7
- id: Args.string({ description: 'graph ID', required: true }),
8
- text: Args.string({ description: 'mutation text', required: true }),
9
- };
10
- static flags = {
11
- privateKey: Flags.string({
12
- description: 'base64-encoded private key',
13
- char: 'k',
14
- env: 'KUBUN_PRIVATE_KEY',
15
- required: true,
16
- }),
17
- url: Flags.string({ description: 'Kubun server URL' }),
18
- variables: Flags.string({ description: 'query variables as JSON string' }),
19
- };
20
- async run() {
21
- const spinner = ora('Executing graph mutation...').start();
22
- const { args, flags } = await this.parse(MutateGraph);
23
- const client = createClient(flags.privateKey, flags.url);
24
- const result = await client.mutateGraph({
25
- id: args.id,
26
- text: args.text,
27
- variables: flags.variables ? JSON.parse(flags.variables) : {},
28
- });
29
- spinner.succeed('Graph mutation executed');
30
- this.log(JSON.stringify(result, null, 2));
31
- }
5
+ static description = 'Execute a GraphQL mutation on a graph'
6
+ static args = {
7
+ id: Args.string({ description: 'graph ID', required: true }),
8
+ text: Args.string({ description: 'mutation text', required: true }),
9
+ }
10
+ static flags = {
11
+ privateKey: Flags.string({
12
+ description: 'base64-encoded private key',
13
+ char: 'k',
14
+ env: 'KUBUN_PRIVATE_KEY',
15
+ required: true,
16
+ }),
17
+ url: Flags.string({ description: 'Kubun server URL' }),
18
+ variables: Flags.string({ description: 'query variables as JSON string' }),
19
+ }
20
+ async run() {
21
+ const spinner = ora('Executing graph mutation...').start()
22
+ const { args, flags } = await this.parse(MutateGraph)
23
+ const client = createClient(flags.privateKey, flags.url)
24
+ const result = await client.mutateGraph({
25
+ id: args.id,
26
+ text: args.text,
27
+ variables: flags.variables ? JSON.parse(flags.variables) : {},
28
+ })
29
+ spinner.succeed('Graph mutation executed')
30
+ this.log(JSON.stringify(result, null, 2))
31
+ }
32
32
  }
@@ -1,32 +1,32 @@
1
- import { Args, Command, Flags } from '@oclif/core';
2
- import ora from 'ora';
3
- import { createClient } from '../../client.js';
1
+ import { Args, Command, Flags } from '@oclif/core'
2
+ import ora from 'ora'
3
+ import { createClient } from '../../client.js'
4
4
  export default class QueryGraph extends Command {
5
- static description = 'Execute a GraphQL query on a graph';
6
- static args = {
7
- id: Args.string({ description: 'graph ID', required: true }),
8
- text: Args.string({ description: 'query text', required: true }),
9
- };
10
- static flags = {
11
- privateKey: Flags.string({
12
- description: 'base64-encoded private key',
13
- char: 'k',
14
- env: 'KUBUN_PRIVATE_KEY',
15
- required: true,
16
- }),
17
- url: Flags.string({ description: 'Kubun server URL' }),
18
- variables: Flags.string({ description: 'query variables as JSON string' }),
19
- };
20
- async run() {
21
- const spinner = ora('Querying graph...').start();
22
- const { args, flags } = await this.parse(QueryGraph);
23
- const client = createClient(flags.privateKey, flags.url);
24
- const result = await client.queryGraph({
25
- id: args.id,
26
- text: args.text,
27
- variables: flags.variables ? JSON.parse(flags.variables) : {},
28
- });
29
- spinner.succeed('Graph query executed');
30
- this.log(JSON.stringify(result, null, 2));
31
- }
5
+ static description = 'Execute a GraphQL query on a graph'
6
+ static args = {
7
+ id: Args.string({ description: 'graph ID', required: true }),
8
+ text: Args.string({ description: 'query text', required: true }),
9
+ }
10
+ static flags = {
11
+ privateKey: Flags.string({
12
+ description: 'base64-encoded private key',
13
+ char: 'k',
14
+ env: 'KUBUN_PRIVATE_KEY',
15
+ required: true,
16
+ }),
17
+ url: Flags.string({ description: 'Kubun server URL' }),
18
+ variables: Flags.string({ description: 'query variables as JSON string' }),
19
+ }
20
+ async run() {
21
+ const spinner = ora('Querying graph...').start()
22
+ const { args, flags } = await this.parse(QueryGraph)
23
+ const client = createClient(flags.privateKey, flags.url)
24
+ const result = await client.queryGraph({
25
+ id: args.id,
26
+ text: args.text,
27
+ variables: flags.variables ? JSON.parse(flags.variables) : {},
28
+ })
29
+ spinner.succeed('Graph query executed')
30
+ this.log(JSON.stringify(result, null, 2))
31
+ }
32
32
  }
@@ -1,46 +1,44 @@
1
- import { ClientSchemaBuilder } from '@kubun/client';
2
- import { GraphModel } from '@kubun/protocol';
3
- import { Command, Flags } from '@oclif/core';
4
- import { printSchema } from 'graphql';
5
- import ora from 'ora';
6
- import { readJSON, writeFile } from '../../fs.js';
1
+ import { createSchema } from '@kubun/graphql'
2
+ import { GraphModel } from '@kubun/protocol'
3
+ import { Command, Flags } from '@oclif/core'
4
+ import { printSchema } from 'graphql'
5
+ import ora from 'ora'
6
+ import { readJSON, writeFile } from '../../fs.js'
7
7
  export default class CreateGraphQLSchema extends Command {
8
- static description = 'Create a GraphQL schema from clusters of document models';
9
- static flags = {
10
- cluster: Flags.string({
11
- description: 'path of the JSON file of the cluster',
12
- char: 'c',
13
- required: true,
14
- multiple: true,
15
- }),
16
- output: Flags.file({
17
- description: 'output file for the GraphQL schema',
18
- char: 'o',
19
- }),
20
- // id: Flags.string({ description: 'graph ID' }),
21
- // privateKey: Flags.string({
22
- // description: 'base64-encoded private key',
23
- // char: 'k',
24
- // env: 'KUBUN_PRIVATE_KEY',
25
- // required: true,
26
- // }),
27
- // url: Flags.string({ description: 'Kubun server URL' }),
28
- };
29
- async run() {
30
- const spinner = ora('Loading clusters...').start();
31
- const { flags } = await this.parse(CreateGraphQLSchema);
32
- const clusters = await Promise.all(flags.cluster.map((path) => readJSON(path)));
33
- const model = await GraphModel.fromClusters({ clusters });
34
- const builder = new ClientSchemaBuilder({ record: model.record });
35
- const schema = printSchema(builder.build());
36
- if (flags.output == null) {
37
- spinner.succeed('GraphQL schema generated');
38
- this.log(schema);
39
- }
40
- else {
41
- await writeFile(flags.output, schema);
42
- spinner.succeed(`GraphQL schema written to ${flags.output}`);
43
- }
44
- return schema;
8
+ static description = 'Create a GraphQL schema from clusters of document models'
9
+ static flags = {
10
+ cluster: Flags.string({
11
+ description: 'path of the JSON file of the cluster',
12
+ char: 'c',
13
+ required: true,
14
+ multiple: true,
15
+ }),
16
+ output: Flags.file({
17
+ description: 'output file for the GraphQL schema',
18
+ char: 'o',
19
+ }),
20
+ // id: Flags.string({ description: 'graph ID' }),
21
+ // privateKey: Flags.string({
22
+ // description: 'base64-encoded private key',
23
+ // char: 'k',
24
+ // env: 'KUBUN_PRIVATE_KEY',
25
+ // required: true,
26
+ // }),
27
+ // url: Flags.string({ description: 'Kubun server URL' }),
28
+ }
29
+ async run() {
30
+ const spinner = ora('Loading clusters...').start()
31
+ const { flags } = await this.parse(CreateGraphQLSchema)
32
+ const clusters = await Promise.all(flags.cluster.map((path) => readJSON(path)))
33
+ const model = await GraphModel.fromClusters({ clusters })
34
+ const schema = printSchema(createSchema(model.record))
35
+ if (flags.output == null) {
36
+ spinner.succeed('GraphQL schema generated')
37
+ this.log(schema)
38
+ } else {
39
+ await writeFile(flags.output, schema)
40
+ spinner.succeed(`GraphQL schema written to ${flags.output}`)
45
41
  }
42
+ return schema
43
+ }
46
44
  }
@@ -1,19 +1,19 @@
1
- import { Args, Command, Flags } from '@oclif/core';
1
+ import { Args, Command, Flags } from '@oclif/core'
2
2
  export default class Hello extends Command {
3
- static args = {
4
- person: Args.string({ description: 'Person to say hello to', required: true }),
5
- };
6
- static description = 'Say hello';
7
- static examples = [
8
- `<%= config.bin %> <%= command.id %> friend --from oclif
3
+ static args = {
4
+ person: Args.string({ description: 'Person to say hello to', required: true }),
5
+ }
6
+ static description = 'Say hello'
7
+ static examples = [
8
+ `<%= config.bin %> <%= command.id %> friend --from oclif
9
9
  hello friend from oclif! (./src/commands/hello/index.ts)
10
10
  `,
11
- ];
12
- static flags = {
13
- from: Flags.string({ char: 'f', description: 'Who is saying hello', required: true }),
14
- };
15
- async run() {
16
- const { args, flags } = await this.parse(Hello);
17
- this.log(`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`);
18
- }
11
+ ]
12
+ static flags = {
13
+ from: Flags.string({ char: 'f', description: 'Who is saying hello', required: true }),
14
+ }
15
+ async run() {
16
+ const { args, flags } = await this.parse(Hello)
17
+ this.log(`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`)
18
+ }
19
19
  }
@@ -1,12 +1,12 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command } from '@oclif/core'
2
2
  export default class World extends Command {
3
- static description = 'Say hello world';
4
- static examples = [
5
- `<%= config.bin %> <%= command.id %>
3
+ static description = 'Say hello world'
4
+ static examples = [
5
+ `<%= config.bin %> <%= command.id %>
6
6
  hello world! (./src/commands/hello/world.ts)
7
7
  `,
8
- ];
9
- async run() {
10
- this.log('hello world! (./src/commands/hello/world.ts)');
11
- }
8
+ ]
9
+ async run() {
10
+ this.log('hello world! (./src/commands/hello/world.ts)')
11
+ }
12
12
  }
@@ -1,35 +1,34 @@
1
- import { ClusterBuilder } from '@kubun/protocol';
2
- import { Command, Flags } from '@oclif/core';
3
- import ora from 'ora';
4
- import { writeJSON } from '../../fs.js';
1
+ import { ClusterBuilder } from '@kubun/protocol'
2
+ import { Command, Flags } from '@oclif/core'
3
+ import ora from 'ora'
4
+ import { writeJSON } from '../../fs.js'
5
5
  export default class CreateClusterModel extends Command {
6
- static description = 'Create a documents cluster model';
7
- static flags = {
8
- model: Flags.string({
9
- description: 'document model as JSON string',
10
- char: 'm',
11
- multiple: true,
12
- required: true,
13
- }),
14
- output: Flags.file({
15
- description: 'output file for the cluster',
16
- char: 'o',
17
- }),
18
- };
19
- async run() {
20
- const spinner = ora('Creating cluster model...').start();
21
- const { flags } = await this.parse(CreateClusterModel);
22
- const builder = new ClusterBuilder();
23
- builder.addAll(flags.model.map((model) => JSON.parse(model)));
24
- const cluster = builder.build();
25
- if (flags.output == null) {
26
- spinner.succeed('Cluster model created');
27
- this.log(JSON.stringify(cluster));
28
- }
29
- else {
30
- await writeJSON(flags.output, cluster);
31
- spinner.succeed(`Cluster model written to ${flags.output}`);
32
- }
33
- return cluster;
6
+ static description = 'Create a documents cluster model'
7
+ static flags = {
8
+ model: Flags.string({
9
+ description: 'document model as JSON string',
10
+ char: 'm',
11
+ multiple: true,
12
+ required: true,
13
+ }),
14
+ output: Flags.file({
15
+ description: 'output file for the cluster',
16
+ char: 'o',
17
+ }),
18
+ }
19
+ async run() {
20
+ const spinner = ora('Creating cluster model...').start()
21
+ const { flags } = await this.parse(CreateClusterModel)
22
+ const builder = new ClusterBuilder()
23
+ builder.addAll(flags.model.map((model) => JSON.parse(model)))
24
+ const cluster = builder.build()
25
+ if (flags.output == null) {
26
+ spinner.succeed('Cluster model created')
27
+ this.log(JSON.stringify(cluster))
28
+ } else {
29
+ await writeJSON(flags.output, cluster)
30
+ spinner.succeed(`Cluster model written to ${flags.output}`)
34
31
  }
32
+ return cluster
33
+ }
35
34
  }
@@ -1,69 +1,67 @@
1
- import { ClusterBuilder, } from '@kubun/protocol';
2
- import { Args, Command, Flags } from '@oclif/core';
3
- import ora from 'ora';
4
- import { writeJSON } from '../../fs.js';
1
+ import { ClusterBuilder } from '@kubun/protocol'
2
+ import { Args, Command, Flags } from '@oclif/core'
3
+ import ora from 'ora'
4
+ import { writeJSON } from '../../fs.js'
5
5
  export default class CreateDocumentModel extends Command {
6
- static description = 'Create a document model';
7
- static args = {
8
- name: Args.string({ description: 'document model name', required: true }),
9
- schema: Args.string({ description: 'document schema as JSON string', required: true }),
10
- };
11
- static flags = {
12
- behavior: Flags.string({
13
- description: 'behavior of the document',
14
- char: 'b',
15
- options: ['default', 'interface', 'unique'],
16
- default: 'default',
17
- }),
18
- cluster: Flags.boolean({
19
- description: 'create a cluster model instead of a document model',
20
- char: 'c',
21
- }),
22
- output: Flags.file({
23
- description: 'output file',
24
- char: 'o',
25
- }),
26
- uniqueField: Flags.string({
27
- description: 'unique field of the document when behavior is set to "unique"',
28
- char: 'u',
29
- multiple: true,
30
- }),
31
- };
32
- async run() {
33
- const spinner = ora('Creating document model...').start();
34
- const { args, flags } = await this.parse(CreateDocumentModel);
35
- const behavior = flags.behavior;
36
- const model = {
37
- name: args.name,
38
- behavior,
39
- schema: JSON.parse(args.schema),
40
- };
41
- if (behavior === 'unique') {
42
- model.uniqueFields = flags.uniqueField;
43
- }
44
- const builder = new ClusterBuilder();
45
- builder.add(model);
46
- if (flags.cluster) {
47
- const cluster = builder.build();
48
- if (flags.output == null) {
49
- spinner.succeed('Cluster model created');
50
- this.log(JSON.stringify(cluster));
51
- }
52
- else {
53
- await writeJSON(flags.output, cluster);
54
- spinner.succeed(`Cluster model written to ${flags.output}`);
55
- }
56
- return cluster;
57
- }
58
- const document = builder.cluster[0];
59
- if (flags.output == null) {
60
- spinner.succeed('Document model created');
61
- this.log(JSON.stringify(document));
62
- }
63
- else {
64
- await writeJSON(flags.output, document);
65
- spinner.succeed(`Document model written to ${flags.output}`);
66
- }
67
- return document;
6
+ static description = 'Create a document model'
7
+ static args = {
8
+ name: Args.string({ description: 'document model name', required: true }),
9
+ schema: Args.string({ description: 'document schema as JSON string', required: true }),
10
+ }
11
+ static flags = {
12
+ behavior: Flags.string({
13
+ description: 'behavior of the document',
14
+ char: 'b',
15
+ options: ['default', 'interface', 'unique'],
16
+ default: 'default',
17
+ }),
18
+ cluster: Flags.boolean({
19
+ description: 'create a cluster model instead of a document model',
20
+ char: 'c',
21
+ }),
22
+ output: Flags.file({
23
+ description: 'output file',
24
+ char: 'o',
25
+ }),
26
+ uniqueField: Flags.string({
27
+ description: 'unique field of the document when behavior is set to "unique"',
28
+ char: 'u',
29
+ multiple: true,
30
+ }),
31
+ }
32
+ async run() {
33
+ const spinner = ora('Creating document model...').start()
34
+ const { args, flags } = await this.parse(CreateDocumentModel)
35
+ const behavior = flags.behavior
36
+ const model = {
37
+ name: args.name,
38
+ behavior,
39
+ schema: JSON.parse(args.schema),
68
40
  }
41
+ if (behavior === 'unique') {
42
+ model.uniqueFields = flags.uniqueField
43
+ }
44
+ const builder = new ClusterBuilder()
45
+ builder.add(model)
46
+ if (flags.cluster) {
47
+ const cluster = builder.build()
48
+ if (flags.output == null) {
49
+ spinner.succeed('Cluster model created')
50
+ this.log(JSON.stringify(cluster))
51
+ } else {
52
+ await writeJSON(flags.output, cluster)
53
+ spinner.succeed(`Cluster model written to ${flags.output}`)
54
+ }
55
+ return cluster
56
+ }
57
+ const document = builder.cluster[0]
58
+ if (flags.output == null) {
59
+ spinner.succeed('Document model created')
60
+ this.log(JSON.stringify(document))
61
+ } else {
62
+ await writeJSON(flags.output, document)
63
+ spinner.succeed(`Document model written to ${flags.output}`)
64
+ }
65
+ return document
66
+ }
69
67
  }
@@ -1,78 +1,75 @@
1
- import { defer } from '@enkaku/async';
2
- import { toB64 } from '@enkaku/codec';
3
- import { ServerTransport } from '@enkaku/http-server-transport';
4
- import { serve } from '@enkaku/server';
5
- import { randomSigner, toTokenSigner } from '@enkaku/token';
6
- import { serve as serveHTTP } from '@hono/node-server';
7
- import { KubunDB } from '@kubun/db';
8
- import { PostgresAdapter } from '@kubun/db-postgres';
9
- import { SQLiteAdapter } from '@kubun/db-sqlite';
10
- import { createHandlers } from '@kubun/server';
11
- import { Command, Flags } from '@oclif/core';
12
- import getPort from 'get-port';
13
- import ora from 'ora';
14
- import { getSigner } from '../account.js';
15
- import { resolvePath } from '../fs.js';
1
+ import { defer } from '@enkaku/async'
2
+ import { toB64 } from '@enkaku/codec'
3
+ import { ServerTransport } from '@enkaku/http-server-transport'
4
+ import { serve } from '@enkaku/server'
5
+ import { randomSigner, toTokenSigner } from '@enkaku/token'
6
+ import { serve as serveHTTP } from '@hono/node-server'
7
+ import { KubunDB } from '@kubun/db'
8
+ import { PostgresAdapter } from '@kubun/db-postgres'
9
+ import { SQLiteAdapter } from '@kubun/db-sqlite'
10
+ import { createHandlers } from '@kubun/server'
11
+ import { Command, Flags } from '@oclif/core'
12
+ import getPort from 'get-port'
13
+ import ora from 'ora'
14
+ import { getSigner } from '../account.js'
15
+ import { resolvePath } from '../fs.js'
16
16
  export default class Serve extends Command {
17
- static description = 'Start a local Kubun server';
18
- static flags = {
19
- db: Flags.file({ description: 'path to the local SQLite database' }),
20
- id: Flags.string({ description: 'server ID' }),
21
- port: Flags.integer({ char: 'p', description: 'port to listen on' }),
22
- privateKey: Flags.string({
23
- char: 'k',
24
- description: 'base64-encoded private key',
25
- env: 'KUBUN_PRIVATE_KEY',
26
- exclusive: ['id'],
27
- }),
28
- };
29
- async run() {
30
- let signer;
31
- const spinner = ora();
32
- const { flags } = await this.parse(Serve);
33
- let id = flags.id;
34
- if (id == null) {
35
- if (flags.privateKey == null) {
36
- spinner.info('Generating a random private key for the server').start();
37
- const ownSigner = randomSigner();
38
- spinner.warn(`Generated private key: ${toB64(ownSigner.privateKey)}`);
39
- signer = toTokenSigner(ownSigner);
40
- }
41
- else {
42
- spinner.info('Using the provided private key for the server').start();
43
- signer = getSigner(flags.privateKey);
44
- }
45
- id = signer.id;
46
- }
47
- spinner.info(`Server DID: ${id}`);
48
- let db;
49
- if (flags.db == null) {
50
- db = new KubunDB({ adapter: new SQLiteAdapter({ database: ':memory:' }) });
51
- spinner.info('Using ephemeral (in memory) SQLite database');
52
- }
53
- else if (flags.db.startsWith('postgres://')) {
54
- db = new KubunDB({ adapter: new PostgresAdapter({ url: flags.db }) });
55
- spinner.info(`Using PostgreSQL database: ${flags.db}`);
56
- }
57
- else {
58
- const database = resolvePath(flags.db);
59
- db = new KubunDB({ adapter: new SQLiteAdapter({ database }) });
60
- spinner.info(`Using local SQLite database: ${database}`);
61
- }
62
- const transport = new ServerTransport();
63
- serve({ handlers: createHandlers({ db }), id, transport });
64
- spinner.start('Starting the server');
65
- const port = flags.port ?? (await getPort({ port: 4321 }));
66
- const httpServer = serveHTTP({ fetch: transport.fetch, port }, (info) => {
67
- spinner.succeed(`HTTP server listening on port ${info.port}`);
68
- });
69
- const stopped = defer();
70
- async function stop() {
71
- httpServer.close();
72
- stopped.resolve();
73
- }
74
- process.on('SIGINT', stop);
75
- process.on('SIGTERM', stop);
76
- return stopped.promise;
17
+ static description = 'Start a local Kubun server'
18
+ static flags = {
19
+ db: Flags.file({ description: 'path to the local SQLite database' }),
20
+ id: Flags.string({ description: 'server ID' }),
21
+ port: Flags.integer({ char: 'p', description: 'port to listen on' }),
22
+ privateKey: Flags.string({
23
+ char: 'k',
24
+ description: 'base64-encoded private key',
25
+ env: 'KUBUN_PRIVATE_KEY',
26
+ exclusive: ['id'],
27
+ }),
28
+ }
29
+ async run() {
30
+ let signer
31
+ const spinner = ora()
32
+ const { flags } = await this.parse(Serve)
33
+ let id = flags.id
34
+ if (id == null) {
35
+ if (flags.privateKey == null) {
36
+ spinner.info('Generating a random private key for the server').start()
37
+ const ownSigner = randomSigner()
38
+ spinner.warn(`Generated private key: ${toB64(ownSigner.privateKey)}`)
39
+ signer = toTokenSigner(ownSigner)
40
+ } else {
41
+ spinner.info('Using the provided private key for the server').start()
42
+ signer = getSigner(flags.privateKey)
43
+ }
44
+ id = signer.id
77
45
  }
46
+ spinner.info(`Server DID: ${id}`)
47
+ let db
48
+ if (flags.db == null) {
49
+ db = new KubunDB({ adapter: new SQLiteAdapter({ database: ':memory:' }) })
50
+ spinner.info('Using ephemeral (in memory) SQLite database')
51
+ } else if (flags.db.startsWith('postgres://')) {
52
+ db = new KubunDB({ adapter: new PostgresAdapter({ url: flags.db }) })
53
+ spinner.info(`Using PostgreSQL database: ${flags.db}`)
54
+ } else {
55
+ const database = resolvePath(flags.db)
56
+ db = new KubunDB({ adapter: new SQLiteAdapter({ database }) })
57
+ spinner.info(`Using local SQLite database: ${database}`)
58
+ }
59
+ const transport = new ServerTransport()
60
+ serve({ handlers: createHandlers({ db }), id, transport })
61
+ spinner.start('Starting the server')
62
+ const port = flags.port ?? (await getPort({ port: 4321 }))
63
+ const httpServer = serveHTTP({ fetch: transport.fetch, port }, (info) => {
64
+ spinner.succeed(`HTTP server listening on port ${info.port}`)
65
+ })
66
+ const stopped = defer()
67
+ async function stop() {
68
+ httpServer.close()
69
+ stopped.resolve()
70
+ }
71
+ process.on('SIGINT', stop)
72
+ process.on('SIGTERM', stop)
73
+ return stopped.promise
74
+ }
78
75
  }
package/dist/fs.js CHANGED
@@ -1,14 +1,14 @@
1
- import { readFile as read, writeFile as write } from 'node:fs/promises';
2
- import { isAbsolute, resolve } from 'node:path';
1
+ import { readFile as read, writeFile as write } from 'node:fs/promises'
2
+ import { isAbsolute, resolve } from 'node:path'
3
3
  export function resolvePath(value) {
4
- return isAbsolute(value) ? value : resolve(process.cwd(), value);
4
+ return isAbsolute(value) ? value : resolve(process.cwd(), value)
5
5
  }
6
6
  export async function readJSON(path) {
7
- return JSON.parse(await read(resolvePath(path), { encoding: 'utf8' }));
7
+ return JSON.parse(await read(resolvePath(path), { encoding: 'utf8' }))
8
8
  }
9
9
  export async function writeFile(path, value) {
10
- await write(resolvePath(path), value, { encoding: 'utf8' });
10
+ await write(resolvePath(path), value, { encoding: 'utf8' })
11
11
  }
12
12
  export async function writeJSON(path, value, format = false) {
13
- await writeFile(path, format ? JSON.stringify(value, null, 2) : JSON.stringify(value));
13
+ await writeFile(path, format ? JSON.stringify(value, null, 2) : JSON.stringify(value))
14
14
  }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { run } from '@oclif/core';
1
+ export { run } from '@oclif/core'
@@ -285,109 +285,6 @@
285
285
  "query.js"
286
286
  ]
287
287
  },
288
- "graphql:schema": {
289
- "aliases": [],
290
- "args": {},
291
- "description": "Create a GraphQL schema from clusters of document models",
292
- "flags": {
293
- "cluster": {
294
- "char": "c",
295
- "description": "path of the JSON file of the cluster",
296
- "name": "cluster",
297
- "required": true,
298
- "hasDynamicHelp": false,
299
- "multiple": true,
300
- "type": "option"
301
- },
302
- "output": {
303
- "char": "o",
304
- "description": "output file for the GraphQL schema",
305
- "name": "output",
306
- "hasDynamicHelp": false,
307
- "multiple": false,
308
- "type": "option"
309
- }
310
- },
311
- "hasDynamicHelp": false,
312
- "hiddenAliases": [],
313
- "id": "graphql:schema",
314
- "pluginAlias": "kubun",
315
- "pluginName": "kubun",
316
- "pluginType": "core",
317
- "strict": true,
318
- "enableJsonFlag": false,
319
- "isESM": true,
320
- "relativePath": [
321
- "dist",
322
- "commands",
323
- "graphql",
324
- "schema.js"
325
- ]
326
- },
327
- "hello": {
328
- "aliases": [],
329
- "args": {
330
- "person": {
331
- "description": "Person to say hello to",
332
- "name": "person",
333
- "required": true
334
- }
335
- },
336
- "description": "Say hello",
337
- "examples": [
338
- "<%= config.bin %> <%= command.id %> friend --from oclif\nhello friend from oclif! (./src/commands/hello/index.ts)\n"
339
- ],
340
- "flags": {
341
- "from": {
342
- "char": "f",
343
- "description": "Who is saying hello",
344
- "name": "from",
345
- "required": true,
346
- "hasDynamicHelp": false,
347
- "multiple": false,
348
- "type": "option"
349
- }
350
- },
351
- "hasDynamicHelp": false,
352
- "hiddenAliases": [],
353
- "id": "hello",
354
- "pluginAlias": "kubun",
355
- "pluginName": "kubun",
356
- "pluginType": "core",
357
- "strict": true,
358
- "enableJsonFlag": false,
359
- "isESM": true,
360
- "relativePath": [
361
- "dist",
362
- "commands",
363
- "hello",
364
- "index.js"
365
- ]
366
- },
367
- "hello:world": {
368
- "aliases": [],
369
- "args": {},
370
- "description": "Say hello world",
371
- "examples": [
372
- "<%= config.bin %> <%= command.id %>\nhello world! (./src/commands/hello/world.ts)\n"
373
- ],
374
- "flags": {},
375
- "hasDynamicHelp": false,
376
- "hiddenAliases": [],
377
- "id": "hello:world",
378
- "pluginAlias": "kubun",
379
- "pluginName": "kubun",
380
- "pluginType": "core",
381
- "strict": true,
382
- "enableJsonFlag": false,
383
- "isESM": true,
384
- "relativePath": [
385
- "dist",
386
- "commands",
387
- "hello",
388
- "world.js"
389
- ]
390
- },
391
288
  "model:cluster": {
392
289
  "aliases": [],
393
290
  "args": {},
@@ -496,7 +393,110 @@
496
393
  "model",
497
394
  "create.js"
498
395
  ]
396
+ },
397
+ "graphql:schema": {
398
+ "aliases": [],
399
+ "args": {},
400
+ "description": "Create a GraphQL schema from clusters of document models",
401
+ "flags": {
402
+ "cluster": {
403
+ "char": "c",
404
+ "description": "path of the JSON file of the cluster",
405
+ "name": "cluster",
406
+ "required": true,
407
+ "hasDynamicHelp": false,
408
+ "multiple": true,
409
+ "type": "option"
410
+ },
411
+ "output": {
412
+ "char": "o",
413
+ "description": "output file for the GraphQL schema",
414
+ "name": "output",
415
+ "hasDynamicHelp": false,
416
+ "multiple": false,
417
+ "type": "option"
418
+ }
419
+ },
420
+ "hasDynamicHelp": false,
421
+ "hiddenAliases": [],
422
+ "id": "graphql:schema",
423
+ "pluginAlias": "kubun",
424
+ "pluginName": "kubun",
425
+ "pluginType": "core",
426
+ "strict": true,
427
+ "enableJsonFlag": false,
428
+ "isESM": true,
429
+ "relativePath": [
430
+ "dist",
431
+ "commands",
432
+ "graphql",
433
+ "schema.js"
434
+ ]
435
+ },
436
+ "hello": {
437
+ "aliases": [],
438
+ "args": {
439
+ "person": {
440
+ "description": "Person to say hello to",
441
+ "name": "person",
442
+ "required": true
443
+ }
444
+ },
445
+ "description": "Say hello",
446
+ "examples": [
447
+ "<%= config.bin %> <%= command.id %> friend --from oclif\nhello friend from oclif! (./src/commands/hello/index.ts)\n"
448
+ ],
449
+ "flags": {
450
+ "from": {
451
+ "char": "f",
452
+ "description": "Who is saying hello",
453
+ "name": "from",
454
+ "required": true,
455
+ "hasDynamicHelp": false,
456
+ "multiple": false,
457
+ "type": "option"
458
+ }
459
+ },
460
+ "hasDynamicHelp": false,
461
+ "hiddenAliases": [],
462
+ "id": "hello",
463
+ "pluginAlias": "kubun",
464
+ "pluginName": "kubun",
465
+ "pluginType": "core",
466
+ "strict": true,
467
+ "enableJsonFlag": false,
468
+ "isESM": true,
469
+ "relativePath": [
470
+ "dist",
471
+ "commands",
472
+ "hello",
473
+ "index.js"
474
+ ]
475
+ },
476
+ "hello:world": {
477
+ "aliases": [],
478
+ "args": {},
479
+ "description": "Say hello world",
480
+ "examples": [
481
+ "<%= config.bin %> <%= command.id %>\nhello world! (./src/commands/hello/world.ts)\n"
482
+ ],
483
+ "flags": {},
484
+ "hasDynamicHelp": false,
485
+ "hiddenAliases": [],
486
+ "id": "hello:world",
487
+ "pluginAlias": "kubun",
488
+ "pluginName": "kubun",
489
+ "pluginType": "core",
490
+ "strict": true,
491
+ "enableJsonFlag": false,
492
+ "isESM": true,
493
+ "relativePath": [
494
+ "dist",
495
+ "commands",
496
+ "hello",
497
+ "world.js"
498
+ ]
499
499
  }
500
500
  },
501
- "version": "0.2.0"
501
+ "version": "0.3.0"
502
502
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubun",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "see LICENSE.md",
5
5
  "description": "Kubun CLI",
6
6
  "keywords": [],
@@ -34,11 +34,11 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@enkaku/async": "^0.11.0",
38
- "@enkaku/codec": "^0.11.0",
39
- "@enkaku/http-server-transport": "^0.11.0",
40
- "@enkaku/server": "^0.11.0",
41
- "@enkaku/token": "^0.11.0",
37
+ "@enkaku/async": "^0.12.0",
38
+ "@enkaku/codec": "^0.12.0",
39
+ "@enkaku/http-server-transport": "^0.12.0",
40
+ "@enkaku/server": "^0.12.0",
41
+ "@enkaku/token": "^0.12.0",
42
42
  "@hono/node-server": "^1.13.7",
43
43
  "@oclif/core": "^4.0.33",
44
44
  "@oclif/plugin-help": "^6",
@@ -46,18 +46,19 @@
46
46
  "get-port": "^7.1.0",
47
47
  "graphql": "^16.9.0",
48
48
  "ora": "^8.1.1",
49
- "@kubun/client": "^0.2.0",
50
- "@kubun/db": "^0.2.0",
51
- "@kubun/db-postgres": "^0.2.0",
52
- "@kubun/db-sqlite": "^0.2.0",
53
- "@kubun/http-client": "^0.2.0",
54
- "@kubun/protocol": "^0.2.0",
55
- "@kubun/server": "^0.2.0"
49
+ "@kubun/client": "^0.3.0",
50
+ "@kubun/db": "^0.3.0",
51
+ "@kubun/db-sqlite": "^0.3.0",
52
+ "@kubun/graphql": "^0.3.0",
53
+ "@kubun/http-client": "^0.3.0",
54
+ "@kubun/db-postgres": "^0.3.0",
55
+ "@kubun/server": "^0.3.0",
56
+ "@kubun/protocol": "^0.3.0"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@oclif/test": "^4.1.12",
59
- "oclif": "^4.17.34",
60
- "shx": "^0.3.3",
60
+ "oclif": "^4.17.42",
61
+ "shx": "^0.4.0",
61
62
  "ts-node": "^10",
62
63
  "typescript": "^5.8.2"
63
64
  },