proteum 2.1.1 → 2.1.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 +25 -6
- package/agents/framework/AGENTS.md +14 -1
- package/agents/project/AGENTS.md +3 -0
- package/cli/commands/create.ts +5 -0
- package/cli/commands/dev.ts +2 -1
- package/cli/commands/init.ts +2 -94
- package/cli/index.ts +1 -4
- package/cli/presentation/commands.ts +45 -9
- package/cli/presentation/devSession.ts +17 -3
- package/cli/presentation/proteum_logo_400x400_square_icon.txt +400 -0
- package/cli/runtime/commands.ts +61 -3
- package/cli/scaffold/index.ts +720 -0
- package/cli/scaffold/templates.ts +344 -0
- package/cli/scaffold/types.ts +26 -0
- package/client/dev/profiler/index.tsx +1230 -230
- package/common/dev/profiler.ts +1 -0
- package/common/dev/requestTrace.ts +6 -0
- package/docs/dev-commands.md +7 -0
- package/docs/diagnostics.md +88 -0
- package/docs/request-tracing.md +10 -0
- package/eslint.js +11 -6
- package/package.json +3 -2
- package/server/app/index.ts +2 -2
- package/server/index.ts +0 -1
- package/server/services/auth/index.ts +525 -61
- package/server/services/auth/router/index.ts +106 -7
- package/server/services/router/http/index.ts +22 -6
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type { TScaffoldInitConfig, TScaffoldResult } from './types';
|
|
2
|
+
|
|
3
|
+
const renderJson = (value: unknown) => JSON.stringify(value, null, 4);
|
|
4
|
+
|
|
5
|
+
export const createPageTemplate = ({
|
|
6
|
+
routePath,
|
|
7
|
+
heading,
|
|
8
|
+
message,
|
|
9
|
+
}: {
|
|
10
|
+
routePath: string;
|
|
11
|
+
heading: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}) => `import Router from '@/client/router';
|
|
14
|
+
|
|
15
|
+
Router.page(
|
|
16
|
+
${JSON.stringify(routePath)},
|
|
17
|
+
() => ({
|
|
18
|
+
_auth: false,
|
|
19
|
+
_layout: false,
|
|
20
|
+
heading: ${JSON.stringify(heading)},
|
|
21
|
+
message: ${JSON.stringify(message)},
|
|
22
|
+
}),
|
|
23
|
+
({ heading, message }) => {
|
|
24
|
+
return (
|
|
25
|
+
<main>
|
|
26
|
+
<h1>{heading}</h1>
|
|
27
|
+
<p>{message}</p>
|
|
28
|
+
</main>
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export const createControllerTemplate = ({
|
|
35
|
+
appIdentifier,
|
|
36
|
+
className,
|
|
37
|
+
methodName,
|
|
38
|
+
}: {
|
|
39
|
+
appIdentifier: string;
|
|
40
|
+
className: string;
|
|
41
|
+
methodName: string;
|
|
42
|
+
}) => `import Controller from '@server/app/controller';
|
|
43
|
+
|
|
44
|
+
export default class ${className} extends Controller<${appIdentifier}> {
|
|
45
|
+
public async ${methodName}() {
|
|
46
|
+
return {
|
|
47
|
+
ok: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
export const createCommandTemplate = ({
|
|
54
|
+
className,
|
|
55
|
+
methodName,
|
|
56
|
+
}: {
|
|
57
|
+
className: string;
|
|
58
|
+
methodName: string;
|
|
59
|
+
}) => `import { Commands } from '@server/app/commands';
|
|
60
|
+
import type App from '@/server/index';
|
|
61
|
+
|
|
62
|
+
export default class ${className} extends Commands<App> {
|
|
63
|
+
public async ${methodName}() {
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
app: this.app.identity.identifier,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
export const createRouteTemplate = ({
|
|
73
|
+
httpMethod,
|
|
74
|
+
routePath,
|
|
75
|
+
}: {
|
|
76
|
+
httpMethod: string;
|
|
77
|
+
routePath: string;
|
|
78
|
+
}) => `import { Router } from '@app';
|
|
79
|
+
|
|
80
|
+
Router.${httpMethod}(${JSON.stringify(routePath)}, {}, async () => {
|
|
81
|
+
return {
|
|
82
|
+
ok: true,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
export const createServiceTemplate = ({
|
|
88
|
+
appIdentifier,
|
|
89
|
+
className,
|
|
90
|
+
}: {
|
|
91
|
+
appIdentifier: string;
|
|
92
|
+
className: string;
|
|
93
|
+
}) => `import Service from '@server/app/service';
|
|
94
|
+
|
|
95
|
+
export type Config = {
|
|
96
|
+
debug?: boolean;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default class ${className} extends Service<Config, {}, ${appIdentifier}, ${appIdentifier}> {
|
|
100
|
+
public async health() {
|
|
101
|
+
return {
|
|
102
|
+
ok: true,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
export const createServiceConfigTemplate = ({
|
|
109
|
+
configExportName,
|
|
110
|
+
serviceImportPath,
|
|
111
|
+
serviceImportName,
|
|
112
|
+
}: {
|
|
113
|
+
configExportName: string;
|
|
114
|
+
serviceImportPath: string;
|
|
115
|
+
serviceImportName: string;
|
|
116
|
+
}) => `import { Services } from '@server/app';
|
|
117
|
+
import ${serviceImportName} from ${JSON.stringify(serviceImportPath)};
|
|
118
|
+
|
|
119
|
+
export const ${configExportName} = Services.config(${serviceImportName}, {});
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
export const createRouterConfigTemplate = () => `import { type ServiceConfig } from '@server/app';
|
|
123
|
+
import AppContainer from '@server/app/container';
|
|
124
|
+
import Router from '@server/services/router';
|
|
125
|
+
|
|
126
|
+
type RouterBaseConfig = Omit<ServiceConfig<typeof Router>, 'plugins'>;
|
|
127
|
+
|
|
128
|
+
const currentDomain = AppContainer.Environment.router.currentDomain;
|
|
129
|
+
const currentUrl = new URL(currentDomain);
|
|
130
|
+
|
|
131
|
+
export const routerBaseConfig = {
|
|
132
|
+
currentDomain,
|
|
133
|
+
http: {
|
|
134
|
+
domain: currentUrl.hostname,
|
|
135
|
+
port: AppContainer.Environment.router.port,
|
|
136
|
+
ssl: currentUrl.protocol === 'https:',
|
|
137
|
+
upload: {
|
|
138
|
+
maxSize: '10mb',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
context: () => ({}),
|
|
142
|
+
} satisfies RouterBaseConfig;
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
export const createServerIndexTemplate = ({ appIdentifier }: { appIdentifier: string }) => `import { Application } from '@server/app';
|
|
146
|
+
import Router from '@server/services/router';
|
|
147
|
+
import SchemaRouter from '@server/services/schema/router';
|
|
148
|
+
|
|
149
|
+
import * as appConfig from '@/server/config/app';
|
|
150
|
+
|
|
151
|
+
export default class ${appIdentifier} extends Application {
|
|
152
|
+
public Router = new Router(
|
|
153
|
+
this,
|
|
154
|
+
{
|
|
155
|
+
...appConfig.routerBaseConfig,
|
|
156
|
+
plugins: {
|
|
157
|
+
schema: new SchemaRouter({}, this),
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
this,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
|
|
165
|
+
export const createClientTsconfigTemplate = () => `{
|
|
166
|
+
"extends": "../node_modules/proteum/tsconfig.common.json",
|
|
167
|
+
"compilerOptions": {
|
|
168
|
+
"rootDir": "..",
|
|
169
|
+
"baseUrl": "..",
|
|
170
|
+
"noImplicitAny": true,
|
|
171
|
+
"noImplicitThis": true,
|
|
172
|
+
"strictBindCallApply": true,
|
|
173
|
+
"useUnknownInCatchVariables": true,
|
|
174
|
+
"paths": {
|
|
175
|
+
"@client/*": ["./node_modules/proteum/client/*"],
|
|
176
|
+
"@common/*": ["./node_modules/proteum/common/*"],
|
|
177
|
+
"@server/*": ["./node_modules/proteum/server/*"],
|
|
178
|
+
|
|
179
|
+
"@/client/context": ["./.proteum/client/context.ts"],
|
|
180
|
+
"@generated/client/*": ["./.proteum/client/*"],
|
|
181
|
+
"@generated/common/*": ["./.proteum/common/*"],
|
|
182
|
+
"@generated/server/*": ["./.proteum/server/*"],
|
|
183
|
+
"@/*": ["./*"],
|
|
184
|
+
|
|
185
|
+
"react": ["./node_modules/preact/compat"],
|
|
186
|
+
"react-dom/test-utils": ["./node_modules/preact/test-utils"],
|
|
187
|
+
"react-dom": ["./node_modules/preact/compat"],
|
|
188
|
+
"react/jsx-runtime": ["./node_modules/preact/jsx-runtime"]
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
"include": [
|
|
192
|
+
".",
|
|
193
|
+
"../var/typings",
|
|
194
|
+
"../node_modules/proteum/types/global",
|
|
195
|
+
"../.proteum/client/services.d.ts",
|
|
196
|
+
"../server/index.ts"
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
`;
|
|
200
|
+
|
|
201
|
+
export const createServerTsconfigTemplate = () => `{
|
|
202
|
+
"extends": "../node_modules/proteum/tsconfig.common.json",
|
|
203
|
+
"compilerOptions": {
|
|
204
|
+
"rootDir": "..",
|
|
205
|
+
"baseUrl": "..",
|
|
206
|
+
"noImplicitAny": true,
|
|
207
|
+
"noImplicitThis": true,
|
|
208
|
+
"strictBindCallApply": true,
|
|
209
|
+
"useUnknownInCatchVariables": true,
|
|
210
|
+
"moduleSuffixes": [".ssr", ""],
|
|
211
|
+
"paths": {
|
|
212
|
+
"@client/*": ["./node_modules/proteum/client/*"],
|
|
213
|
+
"@common/*": ["./node_modules/proteum/common/*"],
|
|
214
|
+
"@server/*": ["./node_modules/proteum/server/*"],
|
|
215
|
+
|
|
216
|
+
"@/client/context": ["./.proteum/client/context.ts"],
|
|
217
|
+
"@generated/client/*": ["./.proteum/client/*"],
|
|
218
|
+
"@generated/common/*": ["./.proteum/common/*"],
|
|
219
|
+
"@generated/server/*": ["./.proteum/server/*"],
|
|
220
|
+
"@/*": ["./*"],
|
|
221
|
+
|
|
222
|
+
"react": ["./node_modules/preact/compat"],
|
|
223
|
+
"react-dom/test-utils": ["./node_modules/preact/test-utils"],
|
|
224
|
+
"react-dom": ["./node_modules/preact/compat"],
|
|
225
|
+
"react/jsx-runtime": ["./node_modules/preact/jsx-runtime"]
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
"include": [
|
|
229
|
+
".",
|
|
230
|
+
"../var/typings",
|
|
231
|
+
"../node_modules/proteum/types/global",
|
|
232
|
+
"../.proteum/server/services.d.ts",
|
|
233
|
+
"../server/index.ts"
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
`;
|
|
237
|
+
|
|
238
|
+
export const createGitignoreTemplate = () => `node_modules
|
|
239
|
+
.proteum
|
|
240
|
+
.cache
|
|
241
|
+
bin
|
|
242
|
+
dev
|
|
243
|
+
var
|
|
244
|
+
.env
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
export const createEnvTemplate = ({ port, url }: { port: number; url: string }) => `ENV_NAME=local
|
|
248
|
+
ENV_PROFILE=dev
|
|
249
|
+
PORT=${port}
|
|
250
|
+
URL=${url}
|
|
251
|
+
|
|
252
|
+
# Optional trace settings
|
|
253
|
+
# TRACE_ENABLE=true
|
|
254
|
+
# TRACE_CAPTURE=resolve
|
|
255
|
+
# TRACE_PERSIST_ON_ERROR=true
|
|
256
|
+
`;
|
|
257
|
+
|
|
258
|
+
export const createEslintConfigTemplate = () => `import proteumEslint from 'proteum/eslint.js';
|
|
259
|
+
|
|
260
|
+
const { createProteumEslintConfig } = proteumEslint;
|
|
261
|
+
|
|
262
|
+
export default createProteumEslintConfig();
|
|
263
|
+
`;
|
|
264
|
+
|
|
265
|
+
export const createPackageJsonTemplate = ({
|
|
266
|
+
packageName,
|
|
267
|
+
appDescription,
|
|
268
|
+
proteumDependency,
|
|
269
|
+
preactDependency,
|
|
270
|
+
}: {
|
|
271
|
+
packageName: string;
|
|
272
|
+
appDescription: string;
|
|
273
|
+
proteumDependency: string;
|
|
274
|
+
preactDependency: string;
|
|
275
|
+
}) =>
|
|
276
|
+
`${renderJson({
|
|
277
|
+
name: packageName,
|
|
278
|
+
version: '0.0.1',
|
|
279
|
+
private: true,
|
|
280
|
+
engines: {
|
|
281
|
+
node: '>=20.19.0',
|
|
282
|
+
npm: '>=3.10.10',
|
|
283
|
+
},
|
|
284
|
+
browserslist: ['>1%', 'not dead', 'not op_mini all'],
|
|
285
|
+
scripts: {
|
|
286
|
+
dev: 'NODE_ENV=development proteum dev',
|
|
287
|
+
refresh: 'npx proteum refresh',
|
|
288
|
+
typecheck: 'npx proteum typecheck',
|
|
289
|
+
lint: 'npx proteum lint',
|
|
290
|
+
check: 'npx proteum check',
|
|
291
|
+
build: 'npx proteum build --prod',
|
|
292
|
+
start: 'NODE_ENV=production node ./bin/server.js',
|
|
293
|
+
},
|
|
294
|
+
description: appDescription,
|
|
295
|
+
dependencies: {
|
|
296
|
+
preact: preactDependency,
|
|
297
|
+
proteum: proteumDependency,
|
|
298
|
+
},
|
|
299
|
+
})}\n`;
|
|
300
|
+
|
|
301
|
+
export const createIdentityTemplate = ({
|
|
302
|
+
appName,
|
|
303
|
+
appIdentifier,
|
|
304
|
+
appDescription,
|
|
305
|
+
}: {
|
|
306
|
+
appName: string;
|
|
307
|
+
appIdentifier: string;
|
|
308
|
+
appDescription: string;
|
|
309
|
+
}) => `name: ${appName}
|
|
310
|
+
identifier: ${appIdentifier}
|
|
311
|
+
description: ${JSON.stringify(appDescription)}
|
|
312
|
+
|
|
313
|
+
author:
|
|
314
|
+
name: ${appName}
|
|
315
|
+
url: localhost
|
|
316
|
+
email: team@example.com
|
|
317
|
+
|
|
318
|
+
social:
|
|
319
|
+
|
|
320
|
+
language: en
|
|
321
|
+
locale: en-US
|
|
322
|
+
maincolor: white
|
|
323
|
+
iconsPack: light
|
|
324
|
+
|
|
325
|
+
web:
|
|
326
|
+
title: ${JSON.stringify(appName)}
|
|
327
|
+
titleSuffix: ${JSON.stringify(appName)}
|
|
328
|
+
fullTitle: ${JSON.stringify(appName)}
|
|
329
|
+
description: ${JSON.stringify(appDescription)}
|
|
330
|
+
version: 0.0.1
|
|
331
|
+
`;
|
|
332
|
+
|
|
333
|
+
export const createInitSummary = (result: TScaffoldResult, config: TScaffoldInitConfig) => ({
|
|
334
|
+
...result,
|
|
335
|
+
project: {
|
|
336
|
+
directory: config.directory,
|
|
337
|
+
name: config.name,
|
|
338
|
+
identifier: config.identifier,
|
|
339
|
+
port: config.port,
|
|
340
|
+
url: config.url,
|
|
341
|
+
proteumDependency: config.proteumDependency,
|
|
342
|
+
install: config.install,
|
|
343
|
+
},
|
|
344
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type TScaffoldKind = 'page' | 'controller' | 'command' | 'route' | 'service';
|
|
2
|
+
|
|
3
|
+
export type TScaffoldFilePlan = {
|
|
4
|
+
relativePath: string;
|
|
5
|
+
content: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type TScaffoldResult = {
|
|
9
|
+
dryRun: boolean;
|
|
10
|
+
created: string[];
|
|
11
|
+
updated: string[];
|
|
12
|
+
skipped: string[];
|
|
13
|
+
notes: string[];
|
|
14
|
+
nextSteps: string[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type TScaffoldInitConfig = {
|
|
18
|
+
directory: string;
|
|
19
|
+
name: string;
|
|
20
|
+
identifier: string;
|
|
21
|
+
description: string;
|
|
22
|
+
port: number;
|
|
23
|
+
url: string;
|
|
24
|
+
install: boolean;
|
|
25
|
+
proteumDependency: string;
|
|
26
|
+
};
|