@jaypie/mcp 0.1.0 โ 0.1.1
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/package.json +4 -3
- package/prompts/Branch_Management.md +34 -0
- package/prompts/Development_Process.md +67 -0
- package/prompts/Jaypie_Agent_Rules.md +110 -0
- package/prompts/Jaypie_Auth0_Express_Mongoose.md +736 -0
- package/prompts/Jaypie_Browser_and_Frontend_Web_Packages.md +18 -0
- package/prompts/Jaypie_CDK_Constructs_and_Patterns.md +156 -0
- package/prompts/Jaypie_CICD_with_GitHub_Actions.md +151 -0
- package/prompts/Jaypie_Commander_CLI_Package.md +166 -0
- package/prompts/Jaypie_Core_Errors_and_Logging.md +39 -0
- package/prompts/Jaypie_Eslint_NPM_Package.md +78 -0
- package/prompts/Jaypie_Ideal_Project_Structure.md +78 -0
- package/prompts/Jaypie_Init_Express_on_Lambda.md +87 -0
- package/prompts/Jaypie_Init_Jaypie_CDK_Package.md +35 -0
- package/prompts/Jaypie_Init_Lambda_Package.md +245 -0
- package/prompts/Jaypie_Init_Monorepo_Project.md +44 -0
- package/prompts/Jaypie_Init_Project_Subpackage.md +70 -0
- package/prompts/Jaypie_Legacy_Patterns.md +11 -0
- package/prompts/Jaypie_Llm_Calls.md +113 -0
- package/prompts/Jaypie_Llm_Tools.md +124 -0
- package/prompts/Jaypie_Mocks_and_Testkit.md +137 -0
- package/prompts/Jaypie_Mongoose_Models_Package.md +231 -0
- package/prompts/Jaypie_Mongoose_with_Express_CRUD.md +1000 -0
- package/prompts/Jaypie_Scrub.md +177 -0
- package/prompts/Write_Efficient_Prompt_Guides.md +48 -0
- package/prompts/Write_and_Maintain_Engaging_Readme.md +67 -0
- package/prompts/templates/cdk-subpackage/bin/cdk.ts +11 -0
- package/prompts/templates/cdk-subpackage/cdk.json +19 -0
- package/prompts/templates/cdk-subpackage/lib/cdk-app.ts +41 -0
- package/prompts/templates/cdk-subpackage/lib/cdk-infrastructure.ts +15 -0
- package/prompts/templates/express-subpackage/index.ts +8 -0
- package/prompts/templates/express-subpackage/src/app.ts +18 -0
- package/prompts/templates/express-subpackage/src/handler.config.ts +44 -0
- package/prompts/templates/express-subpackage/src/routes/resource/__tests__/resourceGet.route.spec.ts +29 -0
- package/prompts/templates/express-subpackage/src/routes/resource/resourceGet.route.ts +22 -0
- package/prompts/templates/express-subpackage/src/routes/resource.router.ts +11 -0
- package/prompts/templates/express-subpackage/src/types/express.ts +9 -0
- package/prompts/templates/project-monorepo/.vscode/settings.json +72 -0
- package/prompts/templates/project-monorepo/eslint.config.mjs +1 -0
- package/prompts/templates/project-monorepo/package.json +20 -0
- package/prompts/templates/project-monorepo/tsconfig.base.json +18 -0
- package/prompts/templates/project-monorepo/tsconfig.json +6 -0
- package/prompts/templates/project-monorepo/vitest.workspace.js +3 -0
- package/prompts/templates/project-subpackage/package.json +16 -0
- package/prompts/templates/project-subpackage/tsconfig.json +11 -0
- package/prompts/templates/project-subpackage/vite.config.ts +21 -0
- package/prompts/templates/project-subpackage/vitest.config.ts +7 -0
- package/prompts/templates/project-subpackage/vitest.setup.ts +6 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: House style beyond linting to keep the repository clean and organized
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Jaypie Scrub File ๐งฝ
|
|
6
|
+
|
|
7
|
+
Repository style rules beyond linting
|
|
8
|
+
|
|
9
|
+
## ๐ Errors
|
|
10
|
+
|
|
11
|
+
Jaypie offers a number of HTTP and special-use errors not limited to:
|
|
12
|
+
`import { BadGatewayError, BadRequestError, ConfigurationError, ForbiddenError, InternalError, NotFoundError, TooManyRequestsError, UnauthorizedError } from "jaypie";`
|
|
13
|
+
|
|
14
|
+
### Prefer to Throw Jaypie Errors
|
|
15
|
+
|
|
16
|
+
* BadGatewayError when an external provider errors
|
|
17
|
+
* InternalError for default 500 errors
|
|
18
|
+
* ConfigurationError is a 500 variant when the problem is traceable to the coding or configuration of the system (incorrect type, incompatible options)
|
|
19
|
+
|
|
20
|
+
<Bad>
|
|
21
|
+
if (!item) {
|
|
22
|
+
log.error("Item not found");
|
|
23
|
+
return {
|
|
24
|
+
statusCode: 404,
|
|
25
|
+
body: JSON.stringify({ error: "Item not found" }),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
</Bad>
|
|
29
|
+
<Good>
|
|
30
|
+
log.error("Item not found");
|
|
31
|
+
throw new NotFoundError();
|
|
32
|
+
</Good>
|
|
33
|
+
|
|
34
|
+
### Throw Jaypie Errors to Return HTTP Errors in Express
|
|
35
|
+
|
|
36
|
+
Inside a Jaypie `expressHandler`, thrown Jaypie errors will return the correct status to the client.
|
|
37
|
+
Never try to alter `res` or return an error status code.
|
|
38
|
+
|
|
39
|
+
### Avoid Custom Error Strings
|
|
40
|
+
|
|
41
|
+
Though supported, rely on default error messages when throwing.
|
|
42
|
+
Custom error messages should be logged.
|
|
43
|
+
|
|
44
|
+
<Bad>
|
|
45
|
+
throw new NotFoundError("Item not found");
|
|
46
|
+
</Bad>
|
|
47
|
+
<Good>
|
|
48
|
+
log.error("Item not found");
|
|
49
|
+
throw new NotFoundError();
|
|
50
|
+
</Good>
|
|
51
|
+
|
|
52
|
+
## ๐งน Linting
|
|
53
|
+
|
|
54
|
+
Use double quotes, trailing commas, and semicolons.
|
|
55
|
+
Do not delete `// eslint-disable-next-line no-shadow` comments; add when shadowing variables, especially `error` in catch blocks.
|
|
56
|
+
|
|
57
|
+
## ๐ข Logging
|
|
58
|
+
|
|
59
|
+
### Levels
|
|
60
|
+
|
|
61
|
+
* Only use `log.trace` in the happy path
|
|
62
|
+
* Use `log.debug` when straying from the happy path
|
|
63
|
+
* Use `log.warn`, `log.error` as needed
|
|
64
|
+
* Avoid the use of `info`
|
|
65
|
+
|
|
66
|
+
### Logging Variables
|
|
67
|
+
|
|
68
|
+
* Log variables with `log.var({ item })`
|
|
69
|
+
* Only use single-key objects
|
|
70
|
+
* The key can be changed for clarity
|
|
71
|
+
* When logging large arrays, objects, and strings, consider logging abridged/truncated value or summary heuristics like length
|
|
72
|
+
|
|
73
|
+
### Do Not Mix Strings and Objects
|
|
74
|
+
|
|
75
|
+
<Bad>
|
|
76
|
+
log.trace("Looking up item", { item: item.id });
|
|
77
|
+
</Bad>
|
|
78
|
+
<Good>
|
|
79
|
+
log.trace(`Looking up item ${item.id}`);
|
|
80
|
+
# OR
|
|
81
|
+
log.trace(`Looking up item`);
|
|
82
|
+
log.var({ item: item.id });
|
|
83
|
+
</Good>
|
|
84
|
+
|
|
85
|
+
### Separate Variables
|
|
86
|
+
|
|
87
|
+
Do not combine into a single call:
|
|
88
|
+
|
|
89
|
+
<Bad>
|
|
90
|
+
log.debug({ userId: String(user.id), groupId: String(user.group) });
|
|
91
|
+
</Bad>
|
|
92
|
+
<Good>
|
|
93
|
+
log.var({ userId: user.id });
|
|
94
|
+
log.var({ groupId: user.group }); // Jaypie will coerce strings
|
|
95
|
+
</Good>
|
|
96
|
+
|
|
97
|
+
### Logging in Catch Statements
|
|
98
|
+
|
|
99
|
+
* Log the highest level first
|
|
100
|
+
* Use warn for errors that are part of normal operations like items not found, unauthorized users
|
|
101
|
+
* Use error for things that should not happen like database connections failing
|
|
102
|
+
* Follow up with lower-level debug and var logs as needed
|
|
103
|
+
|
|
104
|
+
### Prefixing
|
|
105
|
+
|
|
106
|
+
Using a prefix in square brackets helps identify functions and libraries.
|
|
107
|
+
`log.trace("[newRoute] Starting route");`
|
|
108
|
+
|
|
109
|
+
## ๐ Naming Things
|
|
110
|
+
|
|
111
|
+
### Pluralization
|
|
112
|
+
|
|
113
|
+
* Prefer singular
|
|
114
|
+
* Objects should be singular
|
|
115
|
+
* A model is singular. `Model.User`
|
|
116
|
+
* Arrays should be plural
|
|
117
|
+
|
|
118
|
+
## ๐งช Testing
|
|
119
|
+
|
|
120
|
+
Aim for complete coverage of all happy paths, features, and error conditions.
|
|
121
|
+
Whenever possible, confirm mocked functions are called.
|
|
122
|
+
|
|
123
|
+
### Errors
|
|
124
|
+
|
|
125
|
+
Jaypie Testkit includes custom matchers for errors: toBeJaypieError, toThrowBadGatewayError, toThrowBadRequestError, toThrowConfigurationError, toThrowForbiddenError, toThrowGatewayTimeoutError, toThrowInternalError, toThrowJaypieError, toThrowNotFoundError, toThrowUnauthorizedError, toThrowUnavailableError,
|
|
126
|
+
`expect(fn).toThrowBadGatewayError();`
|
|
127
|
+
`await expect(async() => fn()).toThrowBadGatewayError();`
|
|
128
|
+
Do not use `.rejects`
|
|
129
|
+
|
|
130
|
+
### Function Calls
|
|
131
|
+
|
|
132
|
+
* Always test a function was called before testing specific values
|
|
133
|
+
```
|
|
134
|
+
expect(fn).toBeCalled();
|
|
135
|
+
expect(fn).toBeCalledWith(12);
|
|
136
|
+
```
|
|
137
|
+
Avoid overly specific tests on mock values and strings, especially log string.
|
|
138
|
+
Test key values that need to be passed through the application.
|
|
139
|
+
Use asymmetric matchers for mock values and strings.
|
|
140
|
+
|
|
141
|
+
### Mocks
|
|
142
|
+
|
|
143
|
+
* Assume `jaypie` is mocked by `@jaypie/testkit/mock`
|
|
144
|
+
* Both of these should be mocked in the subpackage's `testSetup.js` or `vitest.setup.ts`
|
|
145
|
+
|
|
146
|
+
### No Test Code in Implementations
|
|
147
|
+
|
|
148
|
+
Do not check for test conditions, environment variables, or mocks outside the test logic.
|
|
149
|
+
Production code should never have special handling for test cases.
|
|
150
|
+
All code should be structured to be fully mockable.
|
|
151
|
+
Appropriate use of mocks should allow special handling to be dictated in the test file.
|
|
152
|
+
|
|
153
|
+
### Observability
|
|
154
|
+
|
|
155
|
+
* The primary happy path should check `log.not.toBeCalledAboveTrace()`
|
|
156
|
+
* Check `expect(log.warn).toBeCalled();` for `warn` and `error` on error cases
|
|
157
|
+
* Do not confirm calls to debug, var, or trace.
|
|
158
|
+
|
|
159
|
+
### Organization
|
|
160
|
+
|
|
161
|
+
Each file should have one top-level `describe` block.
|
|
162
|
+
Organize tests in one of seven second-level describe block sections in this order:
|
|
163
|
+
|
|
164
|
+
1. Base Cases - it is the type we expect ("It is a Function"). For functions, the simplest possible call works and returns not undefined ("It Works"). For objects, the expected shape.
|
|
165
|
+
2. Error Conditions - any error handling the code performs
|
|
166
|
+
3. Security - any security checks the code performs
|
|
167
|
+
4. Observability - any logging the code performs
|
|
168
|
+
5. Happy Paths - The most common use case
|
|
169
|
+
6. Features - Features in addition to the happy path
|
|
170
|
+
7. Specific Scenarios - Special cases
|
|
171
|
+
|
|
172
|
+
Omit describe blocks for sections that are not applicable or empty.
|
|
173
|
+
|
|
174
|
+
## ๐ฑ Miscellaneous
|
|
175
|
+
|
|
176
|
+
Alphabetize as much as possible.
|
|
177
|
+
Whenever a hard-coded value like `site: "datadoghq.com"` is used, define a constant at the top of the file, `const DATADOG_SITE = "datadoghq.com"`, and reference that throughout.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Maintaining code-generation agent guides
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Write Efficient Prompt Guides
|
|
6
|
+
|
|
7
|
+
An efficient prompt conveys maximum information in minimal words.
|
|
8
|
+
|
|
9
|
+
## Process
|
|
10
|
+
|
|
11
|
+
If provided with an existing guide, update the guide.
|
|
12
|
+
Apply these standards dogmatically.
|
|
13
|
+
If provided content, create a new guide.
|
|
14
|
+
|
|
15
|
+
## Goals
|
|
16
|
+
|
|
17
|
+
* Apply a crisp, declarative writing style
|
|
18
|
+
* Consider how each phrase can be written for maximum clarity
|
|
19
|
+
* Remove superfluous language
|
|
20
|
+
* Remove tasks only a human can perform
|
|
21
|
+
* Prefer semantic meaning (like headings) and clarity over aesthetic concerns (like font size)
|
|
22
|
+
|
|
23
|
+
## Suggested Outline for a New Guide
|
|
24
|
+
|
|
25
|
+
```markdown
|
|
26
|
+
# Guide title
|
|
27
|
+
|
|
28
|
+
One-line overview of the guide's value
|
|
29
|
+
|
|
30
|
+
## Goal
|
|
31
|
+
|
|
32
|
+
Aim or "outputs" of the guide
|
|
33
|
+
|
|
34
|
+
## Guidelines
|
|
35
|
+
|
|
36
|
+
Assumptions and prerequisites factoring in the implementation
|
|
37
|
+
|
|
38
|
+
## Process
|
|
39
|
+
|
|
40
|
+
Setup and steps to reproduce
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ๐ Studio House Style
|
|
44
|
+
|
|
45
|
+
Focus on clarity using terse and pithy language.
|
|
46
|
+
Place each sentence on its own line to enhance version control diffs.
|
|
47
|
+
Avoid the second-person pronoun; instructions may imply the reader without using โyou.โ
|
|
48
|
+
Reference abstract third persons when a party must be mentioned.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Maintaining human-centric documentation
|
|
3
|
+
globs: README.md
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Write and Maintain an Engaging README.md
|
|
7
|
+
|
|
8
|
+
Engaging READMEs invite all audiences to explore the contents.
|
|
9
|
+
They present documentation in an accessible and organized manner.
|
|
10
|
+
|
|
11
|
+
## ๐ง Maintenance Checklist (Outputs)
|
|
12
|
+
|
|
13
|
+
Ensure all spelling and grammar have been checked.
|
|
14
|
+
Confirm that all external links operate without redirection.
|
|
15
|
+
Verify that external links land on meaningful pages.
|
|
16
|
+
Check markdown syntax.
|
|
17
|
+
|
|
18
|
+
## ๐ฅ Task Prerequisites (Inputs)
|
|
19
|
+
|
|
20
|
+
Most repositories contain an existing README.
|
|
21
|
+
If only a README is provided, review and maintain it without considering drift from the code.
|
|
22
|
+
If code is included, review the provided code and update the README accordingly.
|
|
23
|
+
If no README is present, verify that a README.md file exists before creating a new one.
|
|
24
|
+
|
|
25
|
+
## โ๏ธ Editorial Guidelines
|
|
26
|
+
|
|
27
|
+
Adhere to the existing heading hierarchy.
|
|
28
|
+
Refrain from modifying established sections.
|
|
29
|
+
Maintain the style, tone, and technical formatting already in use.
|
|
30
|
+
Avoid adding emojis if the current document does not use them.
|
|
31
|
+
|
|
32
|
+
## ๐ Suggested Outline
|
|
33
|
+
|
|
34
|
+
Structure the document so that the content flows from the most common audience's high-level needs to a complete reference.
|
|
35
|
+
Avoid creating empty sections.
|
|
36
|
+
|
|
37
|
+
```markdown
|
|
38
|
+
# Document Title
|
|
39
|
+
Description // a tagline or tl;dr that extends beyond the title
|
|
40
|
+
## โ๏ธ Overview โ an introduction for documents of extensive length
|
|
41
|
+
## ๐ฟ Installation - or ## ๐ฟ Setup
|
|
42
|
+
## ๐ Usage โ a quick overview of the most common uses
|
|
43
|
+
## ๐ Reference โ a detailed guide to all uses, ideally arranged alphabetically
|
|
44
|
+
## ๐ป Development โ instructions for setting up a local environment
|
|
45
|
+
## ๐ Deployment โ guidelines for deploying to staging and production environments
|
|
46
|
+
## ๐ฃ๏ธ Roadmap
|
|
47
|
+
## ๐ Changelog
|
|
48
|
+
## ๐ Appendix - or ## ๐๏ธ Footnotes as needed
|
|
49
|
+
## ๐ License โ typically defaulting to โAll rights reserved.โ unless specified otherwise
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## ๐งโ๐ป Technical Audience
|
|
53
|
+
|
|
54
|
+
Assume that the audience is technical and capable of following explicit instructions.
|
|
55
|
+
Include code examples as necessary.
|
|
56
|
+
Declare required import statements at the beginning of example blocks.
|
|
57
|
+
|
|
58
|
+
## ๐ Studio House Style
|
|
59
|
+
|
|
60
|
+
Adhere to the Chicago Manual of Style.
|
|
61
|
+
Focus on clarity using terse and pithy language.
|
|
62
|
+
Apply whitespace around headings to reduce visual clutter.
|
|
63
|
+
Place each sentence on its own line to enhance version control diffs.
|
|
64
|
+
Apply business formal language with dry whimsy when appropriate.
|
|
65
|
+
Emojis may introduce second-level headings and conclude first- or third-level headings as appropriate.
|
|
66
|
+
Avoid the second-person pronoun; instructions may imply the reader without using โyou.โ
|
|
67
|
+
Reference abstract third persons when a party must be mentioned.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import cdk from "aws-cdk-lib";
|
|
4
|
+
import { AppStack } from "../lib/cdk-app.ts";
|
|
5
|
+
import { InfrastructureStack } from "../lib/cdk-infrastructure.ts";
|
|
6
|
+
|
|
7
|
+
const app = new cdk.App();
|
|
8
|
+
|
|
9
|
+
new InfrastructureStack(app, "InfrastructureStack");
|
|
10
|
+
|
|
11
|
+
new AppStack(app, "AppStack");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "npx ts-node --prefer-ts-exts bin/cdk.ts",
|
|
3
|
+
"watch": {
|
|
4
|
+
"include": [
|
|
5
|
+
"**"
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"README.md",
|
|
9
|
+
"cdk*.json",
|
|
10
|
+
"**/*.d.ts",
|
|
11
|
+
"**/*.js",
|
|
12
|
+
"tsconfig.json",
|
|
13
|
+
"package*.json",
|
|
14
|
+
"yarn.lock",
|
|
15
|
+
"node_modules",
|
|
16
|
+
"test"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JaypieAppStack,
|
|
3
|
+
JaypieApiGateway,
|
|
4
|
+
JaypieExpressLambda,
|
|
5
|
+
JaypieMongoDbSecret,
|
|
6
|
+
JaypieLambda,
|
|
7
|
+
} from "@jaypie/constructs";
|
|
8
|
+
|
|
9
|
+
import * as cdk from "aws-cdk-lib";
|
|
10
|
+
import { Construct } from "constructs";
|
|
11
|
+
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
12
|
+
|
|
13
|
+
export class AppStack extends JaypieAppStack {
|
|
14
|
+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
15
|
+
super(scope, id, props);
|
|
16
|
+
|
|
17
|
+
const mongoConnectionString = new JaypieMongoDbSecret(this);
|
|
18
|
+
|
|
19
|
+
const expressLambda = new JaypieExpressLambda(this, "expressLambda", {
|
|
20
|
+
code: lambda.Code.fromAsset("../express"),
|
|
21
|
+
handler: "dist/index.expressLambda",
|
|
22
|
+
secrets: [mongoConnectionString],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
new JaypieApiGateway(this, "apiGateway", {
|
|
26
|
+
handler: expressLambda,
|
|
27
|
+
host: "api.example.com",
|
|
28
|
+
zone: "example.com",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
new JaypieLambda(
|
|
32
|
+
this,
|
|
33
|
+
"lambdaWorker",
|
|
34
|
+
{
|
|
35
|
+
code: lambda.Code.fromAsset("../lambda"),
|
|
36
|
+
handler: "dist/index.lambdaWorker",
|
|
37
|
+
secrets: [mongoConnectionString],
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JaypieInfrastructureStack,
|
|
3
|
+
JaypieWebDeploymentBucket,
|
|
4
|
+
} from "@jaypie/constructs";
|
|
5
|
+
|
|
6
|
+
export class InfrastructureStack extends JaypieInfrastructureStack {
|
|
7
|
+
constructor(scope, id, props = {}) {
|
|
8
|
+
super(scope, id, props);
|
|
9
|
+
|
|
10
|
+
new JaypieWebDeploymentBucket(this, "DeploymentBucket", {
|
|
11
|
+
// * host is not needed if CDK_ENV_WEB_SUBDOMAIN and CDK_ENV_WEB_HOSTED_ZONE or CDK_ENV_HOSTED_ZONE
|
|
12
|
+
// * zone is not needed if CDK_ENV_WEB_HOSTED_ZONE or CDK_ENV_HOSTED_ZONE
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cors, echoRoute, EXPRESS, noContentRoute, notFoundRoute } from "jaypie";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import resourceRouter from "./routes/resource.router.js";
|
|
4
|
+
|
|
5
|
+
const app = express();
|
|
6
|
+
|
|
7
|
+
// Built-in Jaypie routes
|
|
8
|
+
app.get(EXPRESS.PATH.ROOT, noContentRoute);
|
|
9
|
+
app.use("/_sy/echo", cors(), echoRoute);
|
|
10
|
+
|
|
11
|
+
// Application routes
|
|
12
|
+
app.use(/^\/resource$/, cors(), resourceRouter);
|
|
13
|
+
app.use("/resource/", cors(), resourceRouter);
|
|
14
|
+
|
|
15
|
+
// Catch-all
|
|
16
|
+
app.all(EXPRESS.PATH.ANY, notFoundRoute);
|
|
17
|
+
|
|
18
|
+
export default app;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { force } from "jaypie";
|
|
2
|
+
|
|
3
|
+
interface HandlerConfigOptions {
|
|
4
|
+
locals?: Record<string, any>;
|
|
5
|
+
setup?: Array<() => void | Promise<void>>;
|
|
6
|
+
teardown?: Array<() => void | Promise<void>>;
|
|
7
|
+
validate?: Array<() => boolean | Promise<boolean>>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface HandlerConfig {
|
|
11
|
+
name: string;
|
|
12
|
+
locals: Record<string, any>;
|
|
13
|
+
setup: Array<() => void | Promise<void>>;
|
|
14
|
+
teardown: Array<() => void | Promise<void>>;
|
|
15
|
+
validate: Array<() => boolean | Promise<boolean>>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const handlerConfig = (
|
|
19
|
+
nameOrConfig: string | (HandlerConfig & { name: string }),
|
|
20
|
+
options: HandlerConfigOptions = {}
|
|
21
|
+
): HandlerConfig => {
|
|
22
|
+
let name: string;
|
|
23
|
+
let locals: Record<string, any>;
|
|
24
|
+
let setup: Array<() => void | Promise<void>>;
|
|
25
|
+
let teardown: Array<() => void | Promise<void>>;
|
|
26
|
+
let validate: Array<() => boolean | Promise<boolean>>;
|
|
27
|
+
|
|
28
|
+
if (typeof nameOrConfig === "object") {
|
|
29
|
+
({ name, locals = {}, setup = [], teardown = [], validate = [] } = nameOrConfig);
|
|
30
|
+
} else {
|
|
31
|
+
name = nameOrConfig;
|
|
32
|
+
({ locals = {}, setup = [], teardown = [], validate = [] } = options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
name,
|
|
37
|
+
locals: { ...force.object(locals) },
|
|
38
|
+
setup: [...force.array(setup)],
|
|
39
|
+
teardown: [...force.array(teardown)],
|
|
40
|
+
validate: [...force.array(validate)],
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default handlerConfig;
|
package/prompts/templates/express-subpackage/src/routes/resource/__tests__/resourceGet.route.spec.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import resourceGet from "../resourceGet.route.js";
|
|
3
|
+
|
|
4
|
+
describe("Resource Get Route", () => {
|
|
5
|
+
it("returns resource data", async () => {
|
|
6
|
+
const mockRequest = {
|
|
7
|
+
query: { search: "test" },
|
|
8
|
+
locals: {},
|
|
9
|
+
} as any;
|
|
10
|
+
|
|
11
|
+
const response = await resourceGet(mockRequest);
|
|
12
|
+
|
|
13
|
+
expect(response.message).toBe("Resource endpoint");
|
|
14
|
+
expect(response.query).toEqual({ search: "test" });
|
|
15
|
+
expect(response.timestamp).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("handles empty query", async () => {
|
|
19
|
+
const mockRequest = {
|
|
20
|
+
query: {},
|
|
21
|
+
locals: {},
|
|
22
|
+
} as any;
|
|
23
|
+
|
|
24
|
+
const response = await resourceGet(mockRequest);
|
|
25
|
+
|
|
26
|
+
expect(response.message).toBe("Resource endpoint");
|
|
27
|
+
expect(response.query).toEqual({});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expressHandler } from "jaypie";
|
|
2
|
+
import type { Request } from "express";
|
|
3
|
+
import handlerConfig from "../../handler.config.js";
|
|
4
|
+
|
|
5
|
+
interface ResourceGetResponse {
|
|
6
|
+
message: string;
|
|
7
|
+
query: Record<string, any>;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default expressHandler(
|
|
12
|
+
handlerConfig("resourceGet"),
|
|
13
|
+
async (req: Request): Promise<ResourceGetResponse> => {
|
|
14
|
+
const { query } = req;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
message: "Resource endpoint",
|
|
18
|
+
query,
|
|
19
|
+
timestamp: new Date().toISOString(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { EXPRESS } from "jaypie";
|
|
3
|
+
import resourceGetRoute from "./resource/resourceGet.route.js";
|
|
4
|
+
|
|
5
|
+
const router = express.Router();
|
|
6
|
+
router.use(express.json({ strict: false }));
|
|
7
|
+
|
|
8
|
+
// Single example route
|
|
9
|
+
router.get(EXPRESS.PATH.ROOT, resourceGetRoute);
|
|
10
|
+
|
|
11
|
+
export default router;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cSpell.words": [
|
|
3
|
+
"addgroup",
|
|
4
|
+
"adduser",
|
|
5
|
+
"arcxp",
|
|
6
|
+
"autofix",
|
|
7
|
+
"buildvcs",
|
|
8
|
+
"CDKTAG",
|
|
9
|
+
"certificatemanager",
|
|
10
|
+
"cicd",
|
|
11
|
+
"civisibility",
|
|
12
|
+
"clonedeep",
|
|
13
|
+
"codegenie",
|
|
14
|
+
"cogenticat",
|
|
15
|
+
"composables",
|
|
16
|
+
"coreutils",
|
|
17
|
+
"datadoghq",
|
|
18
|
+
"ddsource",
|
|
19
|
+
"ddtags",
|
|
20
|
+
"dnsutils",
|
|
21
|
+
"dushi",
|
|
22
|
+
"e2bdev",
|
|
23
|
+
"ejectability",
|
|
24
|
+
"elif",
|
|
25
|
+
"envsubst",
|
|
26
|
+
"esmodules",
|
|
27
|
+
"Ferdinandi",
|
|
28
|
+
"Finlayson",
|
|
29
|
+
"finlaysonstudio",
|
|
30
|
+
"finstu",
|
|
31
|
+
"finstuapps",
|
|
32
|
+
"fontface",
|
|
33
|
+
"hola",
|
|
34
|
+
"hygen",
|
|
35
|
+
"iconsets",
|
|
36
|
+
"importx",
|
|
37
|
+
"initzero",
|
|
38
|
+
"invokeid",
|
|
39
|
+
"isequal",
|
|
40
|
+
"jaypie",
|
|
41
|
+
"jsonapi",
|
|
42
|
+
"knowdev",
|
|
43
|
+
"knowtrace",
|
|
44
|
+
"modelcontextprotocol",
|
|
45
|
+
"nobuild",
|
|
46
|
+
"npmjs",
|
|
47
|
+
"nuxt",
|
|
48
|
+
"oidc",
|
|
49
|
+
"openmeteo",
|
|
50
|
+
"pinia",
|
|
51
|
+
"pipefail",
|
|
52
|
+
"procps",
|
|
53
|
+
"repomix",
|
|
54
|
+
"retryable",
|
|
55
|
+
"rimfaf",
|
|
56
|
+
"roboto",
|
|
57
|
+
"rollup",
|
|
58
|
+
"sorpresa",
|
|
59
|
+
"ssoins",
|
|
60
|
+
"stddev",
|
|
61
|
+
"subpackages",
|
|
62
|
+
"supertest",
|
|
63
|
+
"testkit",
|
|
64
|
+
"unplugin",
|
|
65
|
+
"vendia",
|
|
66
|
+
"vite",
|
|
67
|
+
"vitest",
|
|
68
|
+
"vuekit",
|
|
69
|
+
"vuetify",
|
|
70
|
+
"wght"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as default } from "@jaypie/eslint";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@project-org/project-name",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": true,
|
|
6
|
+
"workspaces": [
|
|
7
|
+
"packages/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "npm run build --workspaces",
|
|
11
|
+
"clean": "npm run clean --workspaces && npm run clean:root",
|
|
12
|
+
"clean:root": "rimraf node_modules package-lock.json",
|
|
13
|
+
"format": "eslint --fix",
|
|
14
|
+
"format:package": "sort-package-json ./package.json ./packages/*/package.json",
|
|
15
|
+
"lint": "eslint",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest watch",
|
|
18
|
+
"typecheck": "npm run typecheck --workspaces"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"composite": true,
|
|
13
|
+
"paths": {
|
|
14
|
+
"@pkg-a/*": ["packages/pkg-a/src/*"],
|
|
15
|
+
"@pkg-b/*": ["packages/pkg-b/src/*"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@project-org/project-name",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": true,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"clean": "rimfaf dist",
|
|
9
|
+
"format": "eslint --fix",
|
|
10
|
+
"format:package": "sort-package-json",
|
|
11
|
+
"lint": "eslint",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest watch",
|
|
14
|
+
"typecheck": "tsc --noEmit"
|
|
15
|
+
}
|
|
16
|
+
}
|