@karmaniverous/smoz 0.1.8 → 0.2.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/README.md +28 -4
- package/dist/cli/index.cjs +282 -122
- package/package.json +5 -8
- package/templates/{minimal → default}/app/config/app.config.ts +50 -50
- package/templates/{minimal → default}/app/config/openapi.ts +45 -45
- package/templates/{full → default}/app/functions/rest/hello/get/handler.ts +18 -18
- package/templates/{full → default}/app/functions/rest/hello/get/lambda.ts +28 -28
- package/templates/{minimal → default}/app/functions/rest/hello/get/openapi.ts +23 -23
- package/templates/{minimal → default}/app/functions/rest/openapi/get/handler.ts +22 -22
- package/templates/{minimal → default}/app/functions/rest/openapi/get/lambda.ts +29 -29
- package/templates/{full → default}/app/functions/rest/openapi/get/openapi.ts +20 -20
- package/templates/{project → default}/eslint.config.ts +6 -15
- package/templates/default/package.json +44 -0
- package/templates/default/serverless.ts +113 -0
- package/templates/default/tsconfig.eslint.json +13 -0
- package/templates/{minimal → default}/types/registers.d.ts +11 -11
- package/templates/.check/eslint.minimal.config.ts +0 -41
- package/templates/.check/eslint.templates.config.ts +0 -60
- package/templates/.check/tsconfig.eslintconfig.json +0 -6
- package/templates/.check/tsconfig.minimal.json +0 -14
- package/templates/.manifests/package.full.json +0 -22
- package/templates/.manifests/package.minimal.json +0 -22
- package/templates/.manifests/package.project.json +0 -24
- package/templates/full/app/config/app.config.ts +0 -50
- package/templates/full/app/config/openapi.ts +0 -44
- package/templates/full/app/functions/rest/hello/get/openapi.ts +0 -19
- package/templates/full/app/functions/rest/openapi/get/handler.ts +0 -20
- package/templates/full/app/functions/rest/openapi/get/lambda.ts +0 -29
- package/templates/full/app/functions/sqs/tick/handler.ts +0 -7
- package/templates/full/app/functions/sqs/tick/lambda.ts +0 -24
- package/templates/full/app/functions/sqs/tick/serverless.ts +0 -8
- package/templates/full/serverless.ts +0 -33
- package/templates/full/tsconfig.json +0 -25
- package/templates/full/types/registers.d.ts +0 -11
- package/templates/minimal/app/functions/rest/hello/get/handler.ts +0 -18
- package/templates/minimal/app/functions/rest/hello/get/lambda.ts +0 -28
- package/templates/minimal/app/functions/rest/openapi/get/openapi.ts +0 -20
- package/templates/minimal/app/generated/openapi.json +0 -8
- package/templates/minimal/serverless.ts +0 -34
- package/templates/minimal/tsconfig.json +0 -25
- /package/templates/{project → default}/.prettierrc.json +0 -0
- /package/templates/{project → default}/.vscode/extensions.json +0 -0
- /package/templates/{project → default}/.vscode/settings.json +0 -0
- /package/templates/{project → default}/README.md +0 -0
- /package/templates/{full → default}/app/generated/openapi.json +0 -0
- /package/templates/{project → default}/gitignore +0 -0
- /package/templates/{project → default}/test/smoke.test.ts +0 -0
- /package/templates/{project → default}/tsconfig.base.json +0 -0
- /package/templates/{project → default}/tsconfig.json +0 -0
- /package/templates/{project → default}/tsdoc.json +0 -0
- /package/templates/{project → default}/typedoc.json +0 -0
- /package/templates/{project → default}/vitest.config.ts +0 -0
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
|
|
4
|
-
import { App, baseEventTypeMapSchema, toPosixPath } from '@karmaniverous/smoz';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
// Derive the app root as the parent directory of app/config/
|
|
8
|
-
export const APP_ROOT_ABS = toPosixPath(
|
|
9
|
-
fileURLToPath(new URL('..', import.meta.url)),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export const app = App.create({
|
|
13
|
-
appRootAbs: APP_ROOT_ABS,
|
|
14
|
-
globalParamsSchema: z.object({
|
|
15
|
-
PROFILE: z.string(),
|
|
16
|
-
REGION: z.string(),
|
|
17
|
-
SERVICE_NAME: z.string(),
|
|
18
|
-
}),
|
|
19
|
-
stageParamsSchema: z.object({
|
|
20
|
-
STAGE: z.string(),
|
|
21
|
-
}),
|
|
22
|
-
eventTypeMapSchema: baseEventTypeMapSchema,
|
|
23
|
-
serverless: {
|
|
24
|
-
httpContextEventMap: {
|
|
25
|
-
my: {}, // place a Cognito authorizer here if needed
|
|
26
|
-
private: { private: true },
|
|
27
|
-
public: {},
|
|
28
|
-
},
|
|
29
|
-
defaultHandlerFileName: 'handler',
|
|
30
|
-
defaultHandlerFileExport: 'handler',
|
|
31
|
-
},
|
|
32
|
-
global: {
|
|
33
|
-
params: {
|
|
34
|
-
PROFILE: 'dev',
|
|
35
|
-
REGION: 'us-east-1',
|
|
36
|
-
SERVICE_NAME: 'my-smoz-app',
|
|
37
|
-
},
|
|
38
|
-
envKeys: ['PROFILE', 'REGION', 'SERVICE_NAME'] as const,
|
|
39
|
-
},
|
|
40
|
-
stage: {
|
|
41
|
-
params: {
|
|
42
|
-
dev: { STAGE: 'dev' },
|
|
43
|
-
},
|
|
44
|
-
envKeys: ['STAGE'] as const,
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
export const ENDPOINTS_ROOT_REST = toPosixPath(
|
|
49
|
-
join(APP_ROOT_ABS, 'functions', 'rest'),
|
|
50
|
-
);
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
import { App, baseEventTypeMapSchema, toPosixPath } from '@karmaniverous/smoz';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
// Derive the app root as the parent directory of app/config/
|
|
8
|
+
export const APP_ROOT_ABS = toPosixPath(
|
|
9
|
+
fileURLToPath(new URL('..', import.meta.url)),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const app = App.create({
|
|
13
|
+
appRootAbs: APP_ROOT_ABS,
|
|
14
|
+
globalParamsSchema: z.object({
|
|
15
|
+
PROFILE: z.string(),
|
|
16
|
+
REGION: z.string(),
|
|
17
|
+
SERVICE_NAME: z.string(),
|
|
18
|
+
}),
|
|
19
|
+
stageParamsSchema: z.object({
|
|
20
|
+
STAGE: z.string(),
|
|
21
|
+
}),
|
|
22
|
+
eventTypeMapSchema: baseEventTypeMapSchema,
|
|
23
|
+
serverless: {
|
|
24
|
+
httpContextEventMap: {
|
|
25
|
+
my: {}, // place a Cognito authorizer here if needed
|
|
26
|
+
private: { private: true },
|
|
27
|
+
public: {},
|
|
28
|
+
},
|
|
29
|
+
defaultHandlerFileName: 'handler',
|
|
30
|
+
defaultHandlerFileExport: 'handler',
|
|
31
|
+
},
|
|
32
|
+
global: {
|
|
33
|
+
params: {
|
|
34
|
+
PROFILE: 'dev',
|
|
35
|
+
REGION: 'us-east-1',
|
|
36
|
+
SERVICE_NAME: 'my-smoz-app',
|
|
37
|
+
},
|
|
38
|
+
envKeys: ['PROFILE', 'REGION', 'SERVICE_NAME'] as const,
|
|
39
|
+
},
|
|
40
|
+
stage: {
|
|
41
|
+
params: {
|
|
42
|
+
dev: { STAGE: 'dev' },
|
|
43
|
+
},
|
|
44
|
+
envKeys: ['STAGE'] as const,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const ENDPOINTS_ROOT_REST = toPosixPath(
|
|
49
|
+
join(APP_ROOT_ABS, 'functions', 'rest'),
|
|
50
|
+
);
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import * as fs from 'fs-extra';
|
|
4
|
-
import { packageDirectorySync } from 'pkg-dir';
|
|
5
|
-
import { createDocument } from 'zod-openapi';
|
|
6
|
-
|
|
7
|
-
import { app } from '@/app/config/app.config';
|
|
8
|
-
/**
|
|
9
|
-
* Template note:
|
|
10
|
-
* - Templates do NOT commit generated register files under app/generated; they
|
|
11
|
-
* are declared via ambient types (templates/minimal/types/registers.d.ts) so
|
|
12
|
-
* TypeScript can typecheck without artifacts.
|
|
13
|
-
* - To ensure side effects still run (endpoint registration) and to satisfy
|
|
14
|
-
* noUncheckedSideEffectImports, import the register module as a namespace and
|
|
15
|
-
* reference it via `void`.
|
|
16
|
-
* - In real apps, `smoz init` seeds placeholders and `smoz register` rewrites
|
|
17
|
-
* app/generated/register.*.ts at author time.
|
|
18
|
-
*/
|
|
19
|
-
import * as __register_openapi from '@/app/generated/register.openapi';
|
|
20
|
-
void __register_openapi;
|
|
21
|
-
console.log('Generating OpenAPI document...');
|
|
22
|
-
|
|
23
|
-
const paths = app.buildAllOpenApiPaths();
|
|
24
|
-
export const doc = createDocument({
|
|
25
|
-
openapi: '3.1.0',
|
|
26
|
-
servers: [{ description: 'Dev', url: 'http://localhost' }],
|
|
27
|
-
info: {
|
|
28
|
-
title: process.env.npm_package_name ?? 'smoz-app',
|
|
29
|
-
version: process.env.npm_package_version ?? '0.0.0',
|
|
30
|
-
},
|
|
31
|
-
paths,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const pkgDir = packageDirectorySync();
|
|
35
|
-
if (!pkgDir) {
|
|
36
|
-
throw new Error('Could not resolve package root directory');
|
|
37
|
-
}
|
|
38
|
-
const outDir = path.join(pkgDir, 'app', 'generated');
|
|
39
|
-
fs.ensureDirSync(outDir);
|
|
40
|
-
fs.writeFileSync(
|
|
41
|
-
path.join(outDir, 'openapi.json'),
|
|
42
|
-
JSON.stringify(doc, null, 2),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
console.log('Done!');
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import * as fs from 'fs-extra';
|
|
4
|
+
import { packageDirectorySync } from 'pkg-dir';
|
|
5
|
+
import { createDocument } from 'zod-openapi';
|
|
6
|
+
|
|
7
|
+
import { app } from '@/app/config/app.config';
|
|
8
|
+
/**
|
|
9
|
+
* Template note:
|
|
10
|
+
* - Templates do NOT commit generated register files under app/generated; they
|
|
11
|
+
* are declared via ambient types (templates/minimal/types/registers.d.ts) so
|
|
12
|
+
* TypeScript can typecheck without artifacts.
|
|
13
|
+
* - To ensure side effects still run (endpoint registration) and to satisfy
|
|
14
|
+
* noUncheckedSideEffectImports, import the register module as a namespace and
|
|
15
|
+
* reference it via `void`.
|
|
16
|
+
* - In real apps, `smoz init` seeds placeholders and `smoz register` rewrites
|
|
17
|
+
* app/generated/register.*.ts at author time.
|
|
18
|
+
*/
|
|
19
|
+
import * as __register_openapi from '@/app/generated/register.openapi';
|
|
20
|
+
void __register_openapi;
|
|
21
|
+
console.log('Generating OpenAPI document...');
|
|
22
|
+
|
|
23
|
+
const paths = app.buildAllOpenApiPaths();
|
|
24
|
+
export const doc = createDocument({
|
|
25
|
+
openapi: '3.1.0',
|
|
26
|
+
servers: [{ description: 'Dev', url: 'http://localhost' }],
|
|
27
|
+
info: {
|
|
28
|
+
title: process.env.npm_package_name ?? 'smoz-app',
|
|
29
|
+
version: process.env.npm_package_version ?? '0.0.0',
|
|
30
|
+
},
|
|
31
|
+
paths,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const pkgDir = packageDirectorySync();
|
|
35
|
+
if (!pkgDir) {
|
|
36
|
+
throw new Error('Could not resolve package root directory');
|
|
37
|
+
}
|
|
38
|
+
const outDir = path.join(pkgDir, 'app', 'generated');
|
|
39
|
+
fs.ensureDirSync(outDir);
|
|
40
|
+
fs.writeFileSync(
|
|
41
|
+
path.join(outDir, 'openapi.json'),
|
|
42
|
+
JSON.stringify(doc, null, 2),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
console.log('Done!');
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
import type { responseSchema } from './lambda';
|
|
4
|
-
import { fn } from './lambda';
|
|
5
|
-
|
|
6
|
-
type Response = z.infer<typeof responseSchema>;
|
|
7
|
-
|
|
8
|
-
type FnHandlerApi<T> = {
|
|
9
|
-
handler: (impl: () => Promise<T> | T) => (...args: unknown[]) => Promise<T>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const reg = fn as unknown as FnHandlerApi<Response>;
|
|
13
|
-
|
|
14
|
-
export const handler = reg.handler(async () => {
|
|
15
|
-
const res: Response = { ok: true };
|
|
16
|
-
await Promise.resolve(); // satisfy require-await without adding complexity
|
|
17
|
-
return res;
|
|
18
|
-
});
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { responseSchema } from './lambda';
|
|
4
|
+
import { fn } from './lambda';
|
|
5
|
+
|
|
6
|
+
type Response = z.infer<typeof responseSchema>;
|
|
7
|
+
|
|
8
|
+
type FnHandlerApi<T> = {
|
|
9
|
+
handler: (impl: () => Promise<T> | T) => (...args: unknown[]) => Promise<T>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const reg = fn as unknown as FnHandlerApi<Response>;
|
|
13
|
+
|
|
14
|
+
export const handler = reg.handler(async () => {
|
|
15
|
+
const res: Response = { ok: true };
|
|
16
|
+
await Promise.resolve(); // satisfy require-await without adding complexity
|
|
17
|
+
return res;
|
|
18
|
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { toPosixPath } from '@karmaniverous/smoz';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { app, APP_ROOT_ABS } from '@/app/config/app.config';
|
|
7
|
-
|
|
8
|
-
export const eventSchema = z.object({}).optional();
|
|
9
|
-
export const responseSchema = z.object({ ok: z.boolean() });
|
|
10
|
-
type FnApi = {
|
|
11
|
-
handler: <T>(
|
|
12
|
-
impl: () => Promise<T> | T,
|
|
13
|
-
) => (...args: unknown[]) => Promise<T>;
|
|
14
|
-
openapi: (op: unknown) => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const fn = app.defineFunction({
|
|
18
|
-
functionName: 'hello_get',
|
|
19
|
-
eventType: 'rest',
|
|
20
|
-
httpContexts: ['public'],
|
|
21
|
-
method: 'get',
|
|
22
|
-
basePath: 'hello',
|
|
23
|
-
contentType: 'application/json',
|
|
24
|
-
eventSchema,
|
|
25
|
-
responseSchema,
|
|
26
|
-
callerModuleUrl: import.meta.url,
|
|
27
|
-
endpointsRootAbs: toPosixPath(join(APP_ROOT_ABS, 'functions', 'rest')),
|
|
28
|
-
}) as unknown as FnApi;
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { toPosixPath } from '@karmaniverous/smoz';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
import { app, APP_ROOT_ABS } from '@/app/config/app.config';
|
|
7
|
+
|
|
8
|
+
export const eventSchema = z.object({}).optional();
|
|
9
|
+
export const responseSchema = z.object({ ok: z.boolean() });
|
|
10
|
+
type FnApi = {
|
|
11
|
+
handler: <T>(
|
|
12
|
+
impl: () => Promise<T> | T,
|
|
13
|
+
) => (...args: unknown[]) => Promise<T>;
|
|
14
|
+
openapi: (op: unknown) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const fn = app.defineFunction({
|
|
18
|
+
functionName: 'hello_get',
|
|
19
|
+
eventType: 'rest',
|
|
20
|
+
httpContexts: ['public'],
|
|
21
|
+
method: 'get',
|
|
22
|
+
basePath: 'hello',
|
|
23
|
+
contentType: 'application/json',
|
|
24
|
+
eventSchema,
|
|
25
|
+
responseSchema,
|
|
26
|
+
callerModuleUrl: import.meta.url,
|
|
27
|
+
endpointsRootAbs: toPosixPath(join(APP_ROOT_ABS, 'functions', 'rest')),
|
|
28
|
+
}) as unknown as FnApi;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { fn, responseSchema } from './lambda';
|
|
2
|
-
|
|
3
|
-
type FnOpenApiApi = {
|
|
4
|
-
openapi: (op: unknown) => void;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const reg = fn as unknown as FnOpenApiApi;
|
|
8
|
-
|
|
9
|
-
reg.openapi({
|
|
10
|
-
summary: 'Hello',
|
|
11
|
-
description: 'Return a simple OK payload.',
|
|
12
|
-
responses: {
|
|
13
|
-
200: {
|
|
14
|
-
description: 'Ok',
|
|
15
|
-
content: {
|
|
16
|
-
'application/json': { schema: responseSchema },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
tags: ['public'],
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export {};
|
|
1
|
+
import { fn, responseSchema } from './lambda';
|
|
2
|
+
|
|
3
|
+
type FnOpenApiApi = {
|
|
4
|
+
openapi: (op: unknown) => void;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const reg = fn as unknown as FnOpenApiApi;
|
|
8
|
+
|
|
9
|
+
reg.openapi({
|
|
10
|
+
summary: 'Hello',
|
|
11
|
+
description: 'Return a simple OK payload.',
|
|
12
|
+
responses: {
|
|
13
|
+
200: {
|
|
14
|
+
description: 'Ok',
|
|
15
|
+
content: {
|
|
16
|
+
'application/json': { schema: responseSchema },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
tags: ['public'],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export {};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
// Import the document from its real generated location.
|
|
4
|
-
// The template ships a placeholder at app/generated/openapi.json.
|
|
5
|
-
import openapiDoc from '@/app/generated/openapi.json';
|
|
6
|
-
|
|
7
|
-
import type { responseSchema } from './lambda';
|
|
8
|
-
import { fn } from './lambda';
|
|
9
|
-
|
|
10
|
-
type Response = z.infer<typeof responseSchema>;
|
|
11
|
-
type FnHandlerApi<T> = {
|
|
12
|
-
handler: (impl: () => Promise<T> | T) => (...args: unknown[]) => Promise<T>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const reg = fn as unknown as FnHandlerApi<Response>;
|
|
16
|
-
|
|
17
|
-
export const handler = reg.handler(async () => {
|
|
18
|
-
// Tip: run `npm run openapi` to regenerate this file.
|
|
19
|
-
// Trivial await keeps parity with prior style.
|
|
20
|
-
await Promise.resolve();
|
|
21
|
-
return openapiDoc as Response;
|
|
22
|
-
});
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Import the document from its real generated location.
|
|
4
|
+
// The template ships a placeholder at app/generated/openapi.json.
|
|
5
|
+
import openapiDoc from '@/app/generated/openapi.json';
|
|
6
|
+
|
|
7
|
+
import type { responseSchema } from './lambda';
|
|
8
|
+
import { fn } from './lambda';
|
|
9
|
+
|
|
10
|
+
type Response = z.infer<typeof responseSchema>;
|
|
11
|
+
type FnHandlerApi<T> = {
|
|
12
|
+
handler: (impl: () => Promise<T> | T) => (...args: unknown[]) => Promise<T>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const reg = fn as unknown as FnHandlerApi<Response>;
|
|
16
|
+
|
|
17
|
+
export const handler = reg.handler(async () => {
|
|
18
|
+
// Tip: run `npm run openapi` to regenerate this file.
|
|
19
|
+
// Trivial await keeps parity with prior style.
|
|
20
|
+
await Promise.resolve();
|
|
21
|
+
return openapiDoc as Response;
|
|
22
|
+
});
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { toPosixPath } from '@karmaniverous/smoz';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { app, APP_ROOT_ABS } from '@/app/config/app.config';
|
|
7
|
-
|
|
8
|
-
export const eventSchema = z.any().optional();
|
|
9
|
-
export const responseSchema = z.unknown();
|
|
10
|
-
|
|
11
|
-
type FnApi = {
|
|
12
|
-
handler: <T>(
|
|
13
|
-
impl: () => Promise<T> | T,
|
|
14
|
-
) => (...args: unknown[]) => Promise<T>;
|
|
15
|
-
openapi: (op: unknown) => void;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const fn = app.defineFunction({
|
|
19
|
-
functionName: 'openapi_get',
|
|
20
|
-
eventType: 'rest',
|
|
21
|
-
httpContexts: ['public'],
|
|
22
|
-
method: 'get',
|
|
23
|
-
basePath: 'openapi',
|
|
24
|
-
contentType: 'application/json',
|
|
25
|
-
eventSchema,
|
|
26
|
-
responseSchema,
|
|
27
|
-
callerModuleUrl: import.meta.url,
|
|
28
|
-
endpointsRootAbs: toPosixPath(join(APP_ROOT_ABS, 'functions', 'rest')),
|
|
29
|
-
}) as unknown as FnApi;
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { toPosixPath } from '@karmaniverous/smoz';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
import { app, APP_ROOT_ABS } from '@/app/config/app.config';
|
|
7
|
+
|
|
8
|
+
export const eventSchema = z.any().optional();
|
|
9
|
+
export const responseSchema = z.unknown();
|
|
10
|
+
|
|
11
|
+
type FnApi = {
|
|
12
|
+
handler: <T>(
|
|
13
|
+
impl: () => Promise<T> | T,
|
|
14
|
+
) => (...args: unknown[]) => Promise<T>;
|
|
15
|
+
openapi: (op: unknown) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const fn = app.defineFunction({
|
|
19
|
+
functionName: 'openapi_get',
|
|
20
|
+
eventType: 'rest',
|
|
21
|
+
httpContexts: ['public'],
|
|
22
|
+
method: 'get',
|
|
23
|
+
basePath: 'openapi',
|
|
24
|
+
contentType: 'application/json',
|
|
25
|
+
eventSchema,
|
|
26
|
+
responseSchema,
|
|
27
|
+
callerModuleUrl: import.meta.url,
|
|
28
|
+
endpointsRootAbs: toPosixPath(join(APP_ROOT_ABS, 'functions', 'rest')),
|
|
29
|
+
}) as unknown as FnApi;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { fn, responseSchema } from './lambda';
|
|
2
|
-
|
|
3
|
-
type FnOpenApiApi = {
|
|
4
|
-
openapi: (op: unknown) => void;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const reg = fn as unknown as FnOpenApiApi;
|
|
8
|
-
|
|
9
|
-
reg.openapi({
|
|
10
|
-
summary: 'Get OpenAPI document',
|
|
11
|
-
description:
|
|
12
|
-
'Return the OpenAPI 3.1 document. Generate it via "npm run openapi".',
|
|
13
|
-
responses: {
|
|
14
|
-
200: {
|
|
15
|
-
description: 'OpenAPI document',
|
|
16
|
-
content: { 'application/json': { schema: responseSchema } },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
tags: ['openapi'],
|
|
20
|
-
});
|
|
1
|
+
import { fn, responseSchema } from './lambda';
|
|
2
|
+
|
|
3
|
+
type FnOpenApiApi = {
|
|
4
|
+
openapi: (op: unknown) => void;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const reg = fn as unknown as FnOpenApiApi;
|
|
8
|
+
|
|
9
|
+
reg.openapi({
|
|
10
|
+
summary: 'Get OpenAPI document',
|
|
11
|
+
description:
|
|
12
|
+
'Return the OpenAPI 3.1 document. Generate it via "npm run openapi".',
|
|
13
|
+
responses: {
|
|
14
|
+
200: {
|
|
15
|
+
description: 'OpenAPI document',
|
|
16
|
+
content: { 'application/json': { schema: responseSchema } },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
tags: ['openapi'],
|
|
20
|
+
});
|
|
@@ -9,16 +9,6 @@ import { fileURLToPath } from 'url';
|
|
|
9
9
|
const tsconfigRootDir = dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
|
|
11
11
|
export default [
|
|
12
|
-
{
|
|
13
|
-
ignores: [
|
|
14
|
-
'.serverless/**',
|
|
15
|
-
'.tsbuild/**',
|
|
16
|
-
'coverage/**',
|
|
17
|
-
'dist/**',
|
|
18
|
-
'docs/**',
|
|
19
|
-
'node_modules/**',
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
12
|
eslint.configs.recommended,
|
|
23
13
|
...tseslint.configs.strictTypeChecked,
|
|
24
14
|
prettierConfig,
|
|
@@ -26,7 +16,7 @@ export default [
|
|
|
26
16
|
languageOptions: {
|
|
27
17
|
parser: tseslint.parser,
|
|
28
18
|
parserOptions: {
|
|
29
|
-
project: ['./tsconfig.json'],
|
|
19
|
+
project: ['./tsconfig.eslint.json'],
|
|
30
20
|
tsconfigRootDir,
|
|
31
21
|
},
|
|
32
22
|
},
|
|
@@ -36,12 +26,13 @@ export default [
|
|
|
36
26
|
},
|
|
37
27
|
rules: {
|
|
38
28
|
'prettier/prettier': 'error',
|
|
39
|
-
'@typescript-eslint/consistent-type-imports': 'error',
|
|
40
|
-
'@typescript-eslint/no-unused-expressions': 'off',
|
|
41
|
-
'@typescript-eslint/no-unused-vars': 'error',
|
|
42
|
-
'no-unused-vars': 'off',
|
|
43
29
|
'simple-import-sort/imports': 'error',
|
|
44
30
|
'simple-import-sort/exports': 'error',
|
|
31
|
+
'@typescript-eslint/no-empty-object-type': 'off',
|
|
32
|
+
'@typescript-eslint/no-unused-vars': 'error',
|
|
33
|
+
'@typescript-eslint/no-unsafe-assignment': 'error',
|
|
34
|
+
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
35
|
+
'@typescript-eslint/no-unsafe-return': 'error',
|
|
45
36
|
},
|
|
46
37
|
},
|
|
47
38
|
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smoz-template-default",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.0.0",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@middy/core": "^6.4.5",
|
|
8
|
+
"zod": "^4.1.6"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@serverless/typescript": "^4.18.2",
|
|
12
|
+
"@types/node": "^22",
|
|
13
|
+
"eslint": "^9.35.0",
|
|
14
|
+
"eslint-config-prettier": "^10.1.8",
|
|
15
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
16
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
17
|
+
"jiti": "^2.5.1",
|
|
18
|
+
"prettier": "^3.6.2",
|
|
19
|
+
"serverless": "^4.18.2",
|
|
20
|
+
"serverless-apigateway-log-retention": "^1.1.0",
|
|
21
|
+
"serverless-deployment-bucket": "^1.6.0",
|
|
22
|
+
"serverless-domain-manager": "^8.0.0",
|
|
23
|
+
"serverless-offline": "^14.4.0",
|
|
24
|
+
"serverless-plugin-common-excludes": "^4.0.0",
|
|
25
|
+
"tsx": "^4.20.5",
|
|
26
|
+
"typedoc": "^0.28.12",
|
|
27
|
+
"typescript": "^5.9.2",
|
|
28
|
+
"typescript-eslint": "^8.43.0",
|
|
29
|
+
"vitest": "^3.2.4",
|
|
30
|
+
"zod-openapi": "^5.4.1"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"register": "smoz register",
|
|
34
|
+
"openapi": "smoz register && tsx app/config/openapi && prettier -w app/generated/openapi.json",
|
|
35
|
+
"package": "smoz register && serverless package",
|
|
36
|
+
"dev": "smoz dev",
|
|
37
|
+
"dev:offline": "smoz dev --local offline",
|
|
38
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
39
|
+
"lint": "eslint .",
|
|
40
|
+
"lint:fix": "eslint --fix .",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"docs": "typedoc"
|
|
43
|
+
}
|
|
44
|
+
}
|