@travetto/scaffold 6.0.0-rc.1 → 6.0.0-rc.2

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
@@ -24,22 +24,22 @@ $ npx @travetto/scaffold@<version-or-tag>
24
24
 
25
25
  The generator will ask about enabling the following features:
26
26
 
27
- ## Restful Architecture
28
- The [RESTful API](https://github.com/travetto/travetto/tree/main/module/rest#readme "Declarative api for RESTful APIs with support for the dependency injection module.") provides the necessary integration for exposing restful apis. When selecting the `rest` feature, you will need to specify which backend you want to include with your application, the default being [express](https://expressjs.com). Currently you can select from:
27
+ ## Web Application
28
+ The [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative api for Web Applications with support for the dependency injection.") provides the necessary integration for exposing web apis. When selecting the `web` feature, you will need to specify which backend you want to include with your application, the default being [express](https://expressjs.com). Currently you can select from:
29
29
  * [express](https://expressjs.com)
30
30
  * [koa](https://koajs.com/)
31
31
  * [fastify](https://www.fastify.io/)
32
- The code will establish some basic routes, specifically, `GET / ` as the root endpoint. This will return the contents of your `package.json` as an identification operation.
32
+ The code will establish some basic endpoints, specifically, `GET / ` as the root endpoint. This will return the contents of your `package.json` as an identification operation.
33
33
 
34
- ### Additional Rest Features
35
- In addition to the core functionality, the `rest` feature has some useful sub-features. Specifically:
34
+ ### Additional Web Features
35
+ In addition to the core functionality, the `web` feature has some useful sub-features. Specifically:
36
36
 
37
- [OpenAPI Specification](https://github.com/travetto/travetto/tree/main/module/openapi#readme "OpenAPI integration support for the Travetto framework") support for the restful api. This will automatically expose a `openapi.yml` endpoint, and provide the necessary plumbing to support client generation.
37
+ [OpenAPI Specification](https://github.com/travetto/travetto/tree/main/module/openapi#readme "OpenAPI integration support for the Travetto framework") support for the web api. This will automatically expose a `openapi.yml` endpoint, and provide the necessary plumbing to support client generation.
38
38
 
39
39
  [Logging](https://github.com/travetto/travetto/tree/main/module/log#readme "Logging framework that integrates at the console.log level.") support for better formatting, [debug](https://www.npmjs.com/package/debug) like support, and colorized output. This is generally useful for server logs, especially during development.
40
40
 
41
41
  ## Authentication
42
- Authentication is also supported on the Restful endpoints by selecting [Rest Auth](https://github.com/travetto/travetto/tree/main/module/auth-rest#readme "Rest authentication integration support for the Travetto framework") during setup. This will support basic authentication running out of local memory.
42
+ Authentication is also supported on the Web endpoints by selecting [Web Auth](https://github.com/travetto/travetto/tree/main/module/auth-web#readme "Web authentication integration support for the Travetto framework") during setup. This will support basic authentication running out of local memory.
43
43
 
44
44
  ## Testing
45
45
  [Testing](https://github.com/travetto/travetto/tree/main/module/test#readme "Declarative test framework") can also be configured out of the box to provide simple test cases for the data model.
@@ -68,18 +68,18 @@ export class Todo implements ModelType {
68
68
 
69
69
  Basic tests are also included for the `model` to verify that database interaction and functionality is working properly.
70
70
 
71
- ## Rest + Model
72
- In the case both `rest` and `model` features are enabled, the code will produce a controller that exposes the [Todo](https://github.com/travetto/travetto/tree/main/module/scaffold/doc/model.ts#L4) model via restful patterns.
71
+ ## Web + Model
72
+ In the case both `web` and `model` features are enabled, the code will produce a controller that exposes the [Todo](https://github.com/travetto/travetto/tree/main/module/scaffold/doc/model.ts#L4) model via web patterns.
73
73
 
74
74
  **Code: Todo controller**
75
75
  ```typescript
76
- import { Controller, Get, Put, Post, Delete } from '@travetto/rest';
76
+ import { Controller, Get, Put, Post, Delete } from '@travetto/web';
77
77
  import { NotFoundError } from '@travetto/model';
78
78
  import { Inject } from '@travetto/di';
79
79
  import { ModelQuery, ModelQueryCrudSupport } from '@travetto/model-query';
80
80
  import { Schema } from '@travetto/schema';
81
81
 
82
- import { Todo } from './model';
82
+ import { Todo } from './model.ts';
83
83
 
84
84
  @Schema()
85
85
  class Query {
@@ -147,7 +147,7 @@ export class TodoController {
147
147
  ```
148
148
 
149
149
  ## Running
150
- Once finished the application will reflect the modules chosen, and will be ready for execution, if you have configured a runnable application. Currently, this requires the `rest` feature to be selected.
150
+ Once finished the application will reflect the modules chosen, and will be ready for execution, if you have configured a runnable application. Currently, this requires the `web` feature to be selected.
151
151
 
152
152
  **Terminal: Starting the App**
153
153
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/scaffold",
3
- "version": "6.0.0-rc.1",
3
+ "version": "6.0.0-rc.2",
4
4
  "description": "App Scaffold for the Travetto framework",
5
5
  "keywords": [
6
6
  "generator",
@@ -27,13 +27,13 @@
27
27
  "trv-scaffold": "bin/trv-scaffold.js"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/cli": "^6.0.0-rc.1",
31
- "@travetto/runtime": "^6.0.0-rc.1",
30
+ "@travetto/cli": "^6.0.0-rc.2",
31
+ "@travetto/runtime": "^6.0.0-rc.2",
32
32
  "enquirer": "^2.4.1",
33
33
  "mustache": "^4.2.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@travetto/model": "^6.0.0-rc.1",
36
+ "@travetto/model": "^6.0.0-rc.2",
37
37
  "@types/mustache": "^4.2.5"
38
38
  },
39
39
  "travetto": {
@@ -15,28 +15,28 @@
15
15
  "@travetto/model"
16
16
  ]
17
17
  },
18
- "src/rest/todo.ts": {
18
+ "src/web/todo.ts": {
19
19
  "requires": [
20
- "@travetto/rest",
20
+ "@travetto/web",
21
21
  "@travetto/model"
22
22
  ]
23
23
  },
24
- "src/rest/auth.ts": {
24
+ "src/web/auth.ts": {
25
25
  "requires": [
26
- "@travetto/rest",
27
- "@travetto/auth-rest"
26
+ "@travetto/web",
27
+ "@travetto/auth-web"
28
28
  ]
29
29
  },
30
- "src/rest/auth.config.ts": {
30
+ "src/web/auth.config.ts": {
31
31
  "requires": [
32
- "@travetto/rest",
32
+ "@travetto/web",
33
33
  "@travetto/model-memory",
34
- "@travetto/auth-rest"
34
+ "@travetto/auth-web"
35
35
  ]
36
36
  },
37
- "src/rest/primary.ts": {
37
+ "src/web/primary.ts": {
38
38
  "requires": [
39
- "@travetto/rest"
39
+ "@travetto/web"
40
40
  ]
41
41
  },
42
42
  "test/model/todo.ts": {
@@ -27,7 +27,7 @@
27
27
  "scripts": {
28
28
  "watch": "npx trvc watch",
29
29
  "build": "npx trvc build",
30
- "start": "npx trv run:rest",
30
+ "start": "npx trv web:http",
31
31
  "test": "npx trv test",
32
32
  "lint": "npx trv lint"
33
33
  },
@@ -1,9 +1,9 @@
1
- # {{#modules.rest}}
2
- rest:
1
+ # {{#modules.web}}
2
+ web:
3
3
  ssl:
4
4
  active: false
5
5
  context:
6
6
  active: true
7
7
  cors:
8
8
  active: true
9
- # {{/modules.rest}}
9
+ # {{/modules.web}}
@@ -5,7 +5,7 @@ export class Todo implements ModelType {
5
5
  id: string;
6
6
  text: string;
7
7
  completed?: boolean;
8
- // {{#modules.auth_rest}}
8
+ // {{#modules.auth_web}}
9
9
  userId?: string;
10
- // {{/modules.auth_rest}}
10
+ // {{/modules.auth_web}}
11
11
  }
@@ -1,5 +1,5 @@
1
- import { Controller, Get, Post, Redirect } from '@travetto/rest';
2
- import { Login, Authenticated, Logout } from '@travetto/auth-rest';
1
+ import { Controller, Get, Post, Redirect, ContextParam } from '@travetto/web';
2
+ import { Login, Authenticated, Logout } from '@travetto/auth-web';
3
3
  import { Principal } from '@travetto/auth';
4
4
 
5
5
  import { BasicAuthSymbol } from './auth.config';
@@ -10,6 +10,9 @@ import { BasicAuthSymbol } from './auth.config';
10
10
  @Controller('/auth')
11
11
  export class ApiController {
12
12
 
13
+ @ContextParam()
14
+ user: Principal;
15
+
13
16
  @Post('/login')
14
17
  @Login(BasicAuthSymbol)
15
18
  async getAll(): Promise<Redirect> {
@@ -18,8 +21,8 @@ export class ApiController {
18
21
 
19
22
  @Get('/self')
20
23
  @Authenticated()
21
- async getSelf(user: Principal): Promise<Principal> {
22
- return user;
24
+ async getSelf(): Promise<Principal> {
25
+ return this.user;
23
26
  }
24
27
 
25
28
  @Get('/logout')
@@ -1,4 +1,4 @@
1
- import { Controller, Get, QueryParam } from '@travetto/rest';
1
+ import { Controller, Get, QueryParam } from '@travetto/web';
2
2
 
3
3
  @Controller('/')
4
4
  export class SimpleController {
@@ -1,4 +1,4 @@
1
- import { Controller, Get, Put, Post, Delete } from '@travetto/rest';
1
+ import { Controller, Get, Put, Post, Delete } from '@travetto/web';
2
2
  import { NotFoundError } from '@travetto/model';
3
3
  import { Inject } from '@travetto/di';
4
4
  import { ModelQuery } from '@travetto/model-query';
@@ -6,20 +6,20 @@ import { Schema } from '@travetto/schema';
6
6
  // {{#modules.auth}}
7
7
  import { AuthContext } from '@travetto/auth';
8
8
  // {{/modules.auth}}
9
- // {{#modules.auth_rest}}
10
- import { Authenticated } from '@travetto/auth-rest';
11
- // {{/modules.auth_rest}}
9
+ // {{#modules.auth_web}}
10
+ import { Authenticated } from '@travetto/auth-web';
11
+ // {{/modules.auth_web}}
12
12
  // @ts-expect-error
13
13
  import { $_modelService_$ } from '$_modelImport_$';
14
14
 
15
- import { Todo } from '../model/todo';
15
+ import { Todo } from '../model/todo.ts';
16
16
 
17
17
  @Schema()
18
18
  class Query {
19
19
  q: {
20
- // {{#modules.auth_rest}}
20
+ // {{#modules.auth_web}}
21
21
  userId?: string;
22
- // {{/modules.auth_rest}}
22
+ // {{/modules.auth_web}}
23
23
  } = {};
24
24
  }
25
25
 
@@ -27,9 +27,9 @@ class Query {
27
27
  * Controller for managing all aspects of the Todo lifecycle
28
28
  */
29
29
  @Controller('/todo')
30
- // {{#modules.auth_rest}}
30
+ // {{#modules.auth_web}}
31
31
  @Authenticated()
32
- // {{/modules.auth_rest}}
32
+ // {{/modules.auth_web}}
33
33
  export class TodoController {
34
34
 
35
35
  @Inject()
@@ -46,9 +46,9 @@ export class TodoController {
46
46
  @Get('/')
47
47
  async getAll(query: Query): Promise<Todo[]> {
48
48
  query.q ??= {};
49
- // {{#modules.auth_rest}}
49
+ // {{#modules.auth_web}}
50
50
  query.q.userId = this.authContext.principal?.id;
51
- // {{/modules.auth_rest}}
51
+ // {{/modules.auth_web}}
52
52
  return this.source.query(Todo, { where: query.q });
53
53
  }
54
54
 
@@ -58,11 +58,11 @@ export class TodoController {
58
58
  @Get('/:id')
59
59
  async getOne(id: string): Promise<Todo> {
60
60
  const q: ModelQuery<Todo> = { where: { id } };
61
- // {{#modules.auth_rest}}
61
+ // {{#modules.auth_web}}
62
62
  if (typeof q.where !== 'string') {
63
63
  q.where!.userId = this.authContext.principal?.id;
64
64
  }
65
- // {{/modules.auth_rest}}
65
+ // {{/modules.auth_web}}
66
66
  return this.source.queryOne(Todo, q);
67
67
  }
68
68
 
@@ -71,9 +71,9 @@ export class TodoController {
71
71
  */
72
72
  @Post('/')
73
73
  async save(todo: Todo): Promise<Todo> {
74
- // {{#modules.auth_rest}}
74
+ // {{#modules.auth_web}}
75
75
  todo.userId = this.authContext.principal?.id;
76
- // {{/modules.auth_rest}}
76
+ // {{/modules.auth_web}}
77
77
  return this.source.create(Todo, todo);
78
78
  }
79
79
 
@@ -82,9 +82,9 @@ export class TodoController {
82
82
  */
83
83
  @Put('/:id')
84
84
  async update(todo: Todo): Promise<Todo> {
85
- // {{#modules.auth_rest}}
85
+ // {{#modules.auth_web}}
86
86
  todo.userId = this.authContext.principal?.id;
87
- // {{/modules.auth_rest}}
87
+ // {{/modules.auth_web}}
88
88
  return this.source.update(Todo, todo);
89
89
  }
90
90
 
@@ -94,11 +94,11 @@ export class TodoController {
94
94
  @Delete('/:id')
95
95
  async remove(id: string): Promise<void> {
96
96
  const q: ModelQuery<Todo> = { where: { id } };
97
- // {{#modules.auth_rest}}
97
+ // {{#modules.auth_web}}
98
98
  if (typeof q.where !== 'string') {
99
99
  q.where!.userId = this.authContext.principal?.id;
100
100
  }
101
- // {{/modules.auth_rest}}
101
+ // {{/modules.auth_web}}
102
102
  if (await this.source.deleteByQuery(Todo, q) !== 1) {
103
103
  throw new NotFoundError(Todo, id);
104
104
  }
@@ -2,13 +2,13 @@ import assert from 'node:assert';
2
2
 
3
3
  import { Suite, Test } from '@travetto/test';
4
4
  import { ModelCrudSupport } from '@travetto/model';
5
- import { BaseModelSuite } from '@travetto/model/support/test/base';
5
+ import { BaseModelSuite } from '@travetto/model/support/test/base.ts';
6
6
  import { $_modelConfig_$, $_modelService_$ } from '$_modelImport_$';
7
7
 
8
- import { Todo } from '../../src/model/todo';
8
+ import { Todo } from '../../src/model/todo.ts';
9
9
 
10
10
  @Suite('Simple CRUD')
11
- class TestCRUD extends BaseModelSuite<ModelCrudSupport> {
11
+ class TestCRUD extends BaseModelSuite<ModelCrudSupport> {
12
12
 
13
13
  serviceClass = $_modelService_$;
14
14
  configClass = $_modelConfig_$;
@@ -9,7 +9,7 @@ import { cliTpl } from '@travetto/cli';
9
9
  import { NodePackageManager, PackageUtil } from '@travetto/manifest';
10
10
  import { Terminal } from '@travetto/terminal';
11
11
 
12
- import { Feature } from './features';
12
+ import { Feature } from './features.ts';
13
13
 
14
14
  type ListingEntry = { requires?: string[], rename?: string };
15
15
  type Listing = Record<string, ListingEntry>;
@@ -122,8 +122,8 @@ export class Context {
122
122
  name: this.name,
123
123
  modules,
124
124
  moduleNames,
125
- dependencies: [...new Set(this.#dependencies)].sort((a, b) => a.localeCompare(b)),
126
- devDependencies: [...new Set(this.#devDependencies)].sort((a, b) => a.localeCompare(b)),
125
+ dependencies: [...new Set(this.#dependencies)].toSorted((a, b) => a.localeCompare(b)),
126
+ devDependencies: [...new Set(this.#devDependencies)].toSorted((a, b) => a.localeCompare(b)),
127
127
  }, ...this.#featureContexts);
128
128
 
129
129
  return context;
@@ -23,15 +23,11 @@ export const FEATURES: Feature[] = [
23
23
  default: 'npm'
24
24
  },
25
25
  {
26
- title: 'Rest Framework',
27
- package: '@travetto/rest',
26
+ title: 'Web Framework',
27
+ package: '@travetto/web',
28
28
  choices: [
29
- { title: 'Express.js', package: '@travetto/rest-express' },
30
- { title: 'Express.js Lambda', package: '@travetto/rest-express-lambda' },
31
- { title: 'KOA', package: '@travetto/rest-koa' },
32
- { title: 'KOA Lambda', package: '@travetto/rest-koa-lambda' },
33
- { title: 'Fastify', package: '@travetto/rest-fastify' },
34
- { title: 'Fastify Lambda', package: '@travetto/rest-fastify-lambda' },
29
+ { title: 'Node', package: '@travetto/web-node' },
30
+ { title: 'AWS Lambda', package: '@travetto/web-aws-lambda' },
35
31
  ],
36
32
  addons: [
37
33
  { title: 'OpenAPI', package: '@travetto/openapi' },
@@ -42,10 +38,10 @@ export const FEATURES: Feature[] = [
42
38
  { title: 'Test Framework', package: '@travetto/test' },
43
39
  { title: 'ESLint Support', package: '@travetto/eslint' },
44
40
  {
45
- title: 'Rest Authentication',
46
- package: '@travetto/auth-rest',
41
+ title: 'Web Authentication',
42
+ package: '@travetto/auth-web',
47
43
  addons: [
48
- { title: 'Session Support', package: ['@travetto/auth-session', '@travetto/auth-rest-session', '@travetto/model-memory'] },
44
+ { title: 'Session Support', package: ['@travetto/auth-session', '@travetto/auth-web-session', '@travetto/model-memory'] },
49
45
  ]
50
46
  },
51
47
  {
@@ -5,8 +5,8 @@ import { prompt } from 'enquirer';
5
5
  import { CliCommandShape, CliCommand, cliTpl } from '@travetto/cli';
6
6
  import { Terminal } from '@travetto/terminal';
7
7
 
8
- import { Context } from './bin/context';
9
- import { Feature, FEATURES } from './bin/features';
8
+ import { Context } from './bin/context.ts';
9
+ import { Feature, FEATURES } from './bin/features.ts';
10
10
 
11
11
  /**
12
12
  * Command to run scaffolding
@@ -24,14 +24,14 @@ export class ScaffoldCommand implements CliCommandShape {
24
24
 
25
25
  async #getName(name?: string): Promise<string> {
26
26
  if (!name) {
27
- const res = await prompt<{ name: string }>([
27
+ const response = await prompt<{ name: string }>([
28
28
  {
29
29
  type: 'input',
30
30
  name: 'name',
31
31
  message: 'Enter a name for application: '
32
32
  }
33
33
  ]);
34
- name = res.name;
34
+ name = response.name;
35
35
  }
36
36
  return name;
37
37
  }
@@ -45,8 +45,8 @@ export class ScaffoldCommand implements CliCommandShape {
45
45
  choices: feature.choices!.map(x => x.title).filter((x?: string): x is string => !!x),
46
46
  };
47
47
 
48
- const res = await prompt<{ choice: string }>(choice);
49
- return feature.choices?.find(x => x.title === res.choice);
48
+ const response = await prompt<{ choice: string }>(choice);
49
+ return feature.choices?.find(x => x.title === response.choice);
50
50
  }
51
51
 
52
52
  async * #resolveFeatures(features: Feature[], chosen = false): AsyncGenerator<Feature> {