@taicode/common-server 4.0.0-beta.2 → 4.0.0-beta.4
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/output/app/index.d.ts +13 -15
- package/output/app/index.d.ts.map +1 -1
- package/output/app/index.js +256 -18
- package/output/auth/index.d.ts +72 -0
- package/output/auth/index.d.ts.map +1 -0
- package/output/auth/index.js +176 -0
- package/output/core/assemble.d.ts +64 -0
- package/output/core/assemble.d.ts.map +1 -0
- package/output/core/assemble.js +88 -0
- package/output/core/boot/context.d.ts +89 -0
- package/output/core/boot/context.d.ts.map +1 -0
- package/output/core/boot/context.js +106 -0
- package/output/core/boot/lifecycle.d.ts +94 -0
- package/output/core/boot/lifecycle.d.ts.map +1 -0
- package/output/{app → core/boot}/lifecycle.js +45 -14
- package/output/core/boot/shutdown.d.ts +30 -0
- package/output/core/boot/shutdown.d.ts.map +1 -0
- package/output/core/boot/shutdown.js +45 -0
- package/output/core/boot/signal.d.ts +13 -0
- package/output/core/boot/signal.d.ts.map +1 -0
- package/output/{app → core/boot}/signal.js +3 -2
- package/output/core/boot/steps.d.ts +107 -0
- package/output/core/boot/steps.d.ts.map +1 -0
- package/output/core/boot/steps.js +200 -0
- package/output/core/entries.d.ts +123 -0
- package/output/core/entries.d.ts.map +1 -0
- package/output/core/entries.js +193 -0
- package/output/core/entries.test.d.ts +2 -0
- package/output/core/entries.test.d.ts.map +1 -0
- package/output/core/entries.test.js +217 -0
- package/output/core/env.d.ts +62 -0
- package/output/core/env.d.ts.map +1 -0
- package/output/core/env.js +96 -0
- package/output/{app → core}/env.test.d.ts.map +1 -1
- package/output/core/env.test.js +105 -0
- package/output/core/modules/auth-provider/index.d.ts +10 -0
- package/output/core/modules/auth-provider/index.d.ts.map +1 -0
- package/output/core/modules/auth-provider/index.js +9 -0
- package/output/core/modules/auth-provider/types.d.ts +71 -0
- package/output/core/modules/auth-provider/types.d.ts.map +1 -0
- package/output/core/modules/context/index.d.ts +18 -0
- package/output/core/modules/context/index.d.ts.map +1 -0
- package/output/core/modules/context/index.js +23 -0
- package/output/core/modules/context/index.test.d.ts.map +1 -0
- package/output/core/modules/cookie/index.d.ts +21 -0
- package/output/core/modules/cookie/index.d.ts.map +1 -0
- package/output/{app/core/cookie.js → core/modules/cookie/index.js} +1 -6
- package/output/core/modules/identity/index.d.ts +4 -0
- package/output/core/modules/identity/index.d.ts.map +1 -0
- package/output/{app/core/identity.js → core/modules/identity/index.js} +1 -1
- package/output/core/modules/logging/index.d.ts +5 -0
- package/output/core/modules/logging/index.d.ts.map +1 -0
- package/output/{app/core/logging.js → core/modules/logging/index.js} +2 -2
- package/output/core/modules/openapi/index.d.ts +7 -0
- package/output/core/modules/openapi/index.d.ts.map +1 -0
- package/output/{app/core/openapi.js → core/modules/openapi/index.js} +11 -12
- package/output/core/modules/permission-operations/index.d.ts +26 -0
- package/output/core/modules/permission-operations/index.d.ts.map +1 -0
- package/output/core/modules/permission-operations/index.js +36 -0
- package/output/core/modules/permission-operations/index.test.d.ts +2 -0
- package/output/core/modules/permission-operations/index.test.d.ts.map +1 -0
- package/output/core/modules/permission-operations/index.test.js +45 -0
- package/output/{app/core/request-id.d.ts → core/modules/request-id/index.d.ts} +1 -4
- package/output/core/modules/request-id/index.d.ts.map +1 -0
- package/output/{app/core/request-id.js → core/modules/request-id/index.js} +2 -2
- package/output/core/modules/response/index.d.ts +22 -0
- package/output/core/modules/response/index.d.ts.map +1 -0
- package/output/{app/core/response.js → core/modules/response/index.js} +22 -11
- package/output/{schema/index.d.ts → core/modules/schema/builders.d.ts} +8 -1
- package/output/core/modules/schema/builders.d.ts.map +1 -0
- package/output/{schema/index.js → core/modules/schema/builders.js} +7 -4
- package/output/core/modules/schema/index.d.ts +34 -0
- package/output/core/modules/schema/index.d.ts.map +1 -0
- package/output/core/modules/schema/index.js +62 -0
- package/output/core/modules/schema/index.test.d.ts +2 -0
- package/output/core/modules/schema/index.test.d.ts.map +1 -0
- package/output/core/modules/schema/index.test.js +55 -0
- package/output/core/modules/system-routes/index.d.ts +15 -0
- package/output/core/modules/system-routes/index.d.ts.map +1 -0
- package/output/core/modules/system-routes/index.js +171 -0
- package/output/core/test-support/database.d.ts +96 -0
- package/output/core/test-support/database.d.ts.map +1 -0
- package/output/core/test-support/database.js +144 -0
- package/output/core/test-support/database.test.d.ts +2 -0
- package/output/core/test-support/database.test.d.ts.map +1 -0
- package/output/core/test-support/database.test.js +110 -0
- package/output/core/test-support/environment.d.ts +33 -0
- package/output/core/test-support/environment.d.ts.map +1 -0
- package/output/core/test-support/environment.js +42 -0
- package/output/core/test-support/test-server.d.ts +94 -0
- package/output/core/test-support/test-server.d.ts.map +1 -0
- package/output/core/test-support/test-server.js +60 -0
- package/output/core/test-support/test-server.test.d.ts +2 -0
- package/output/core/test-support/test-server.test.d.ts.map +1 -0
- package/output/core/test-support/test-server.test.js +162 -0
- package/output/{app → core}/type-augment.d.ts +2 -2
- package/output/core/type-augment.d.ts.map +1 -0
- package/output/core/types.d.ts +338 -0
- package/output/core/types.d.ts.map +1 -0
- package/output/cors/index.d.ts +3 -0
- package/output/cors/index.d.ts.map +1 -0
- package/output/cors/index.js +27 -0
- package/output/index.d.ts +8 -4
- package/output/index.d.ts.map +1 -1
- package/output/index.js +24 -5
- package/output/rate-limit/index.d.ts +23 -0
- package/output/rate-limit/index.d.ts.map +1 -0
- package/output/rate-limit/index.js +42 -0
- package/output/{rate-limiter/rate-limiter.d.ts → rate-limit/limiter.d.ts} +1 -1
- package/output/rate-limit/limiter.d.ts.map +1 -0
- package/output/rate-limit/memory-store.d.ts.map +1 -0
- package/output/rate-limit/redis-store.d.ts.map +1 -0
- package/output/rate-limit/redis-store.test.d.ts.map +1 -0
- package/output/{rate-limiter → rate-limit}/redis-store.test.js +2 -2
- package/output/{rate-limiter → rate-limit}/types.d.ts +0 -1
- package/output/rate-limit/types.d.ts.map +1 -0
- package/output/rate-limit/types.js +1 -0
- package/output/{redis-cache/redis-cache.d.ts → redis/cache.d.ts} +1 -1
- package/output/redis/cache.d.ts.map +1 -0
- package/output/redis/cache.test.d.ts +2 -0
- package/output/redis/cache.test.d.ts.map +1 -0
- package/output/{redis-cache/redis-cache.test.js → redis/cache.test.js} +1 -1
- package/output/{app/redis.d.ts → redis/index.d.ts} +12 -7
- package/output/redis/index.d.ts.map +1 -0
- package/output/{app/redis.js → redis/index.js} +15 -5
- package/output/redis/index.test.d.ts +2 -0
- package/output/{context → redis}/index.test.d.ts.map +1 -1
- package/output/redis/index.test.js +55 -0
- package/output/redis-queue/index.js +1 -1
- package/output/redis-queue/test-helpers.d.ts +1 -1
- package/output/redis-queue/test-helpers.js +1 -1
- package/output/redis-queue/types.d.ts +3 -12
- package/output/redis-queue/types.d.ts.map +1 -1
- package/package.json +16 -15
- package/LICENSE +0 -21
- package/output/app/auth.test.d.ts +0 -2
- package/output/app/auth.test.d.ts.map +0 -1
- package/output/app/auth.test.js +0 -148
- package/output/app/boot.d.ts +0 -39
- package/output/app/boot.d.ts.map +0 -1
- package/output/app/boot.js +0 -140
- package/output/app/config.test.d.ts +0 -2
- package/output/app/config.test.d.ts.map +0 -1
- package/output/app/config.test.js +0 -132
- package/output/app/context.d.ts +0 -70
- package/output/app/context.d.ts.map +0 -1
- package/output/app/context.js +0 -73
- package/output/app/core/cookie.d.ts +0 -25
- package/output/app/core/cookie.d.ts.map +0 -1
- package/output/app/core/identity.d.ts +0 -12
- package/output/app/core/identity.d.ts.map +0 -1
- package/output/app/core/index.d.ts +0 -44
- package/output/app/core/index.d.ts.map +0 -1
- package/output/app/core/index.js +0 -57
- package/output/app/core/logging.d.ts +0 -13
- package/output/app/core/logging.d.ts.map +0 -1
- package/output/app/core/openapi.d.ts +0 -17
- package/output/app/core/openapi.d.ts.map +0 -1
- package/output/app/core/request-id.d.ts.map +0 -1
- package/output/app/core/response.d.ts +0 -41
- package/output/app/core/response.d.ts.map +0 -1
- package/output/app/define-server.negative-cases.d.ts +0 -40
- package/output/app/define-server.negative-cases.d.ts.map +0 -1
- package/output/app/define-server.negative-cases.js +0 -268
- package/output/app/define-server.test.d.ts +0 -2
- package/output/app/define-server.test.d.ts.map +0 -1
- package/output/app/define-server.test.js +0 -97
- package/output/app/entries.d.ts +0 -29
- package/output/app/entries.d.ts.map +0 -1
- package/output/app/entries.js +0 -64
- package/output/app/env.d.ts +0 -59
- package/output/app/env.d.ts.map +0 -1
- package/output/app/env.js +0 -66
- package/output/app/env.test.js +0 -124
- package/output/app/error-contract.test.d.ts +0 -2
- package/output/app/error-contract.test.d.ts.map +0 -1
- package/output/app/error-contract.test.js +0 -227
- package/output/app/errors.d.ts +0 -20
- package/output/app/errors.d.ts.map +0 -1
- package/output/app/errors.js +0 -51
- package/output/app/generate-openapi.test.d.ts +0 -2
- package/output/app/generate-openapi.test.d.ts.map +0 -1
- package/output/app/generate-openapi.test.js +0 -123
- package/output/app/lifecycle-logging.test.d.ts +0 -2
- package/output/app/lifecycle-logging.test.d.ts.map +0 -1
- package/output/app/lifecycle-logging.test.js +0 -155
- package/output/app/lifecycle.d.ts +0 -70
- package/output/app/lifecycle.d.ts.map +0 -1
- package/output/app/lifecycle.test.d.ts +0 -2
- package/output/app/lifecycle.test.d.ts.map +0 -1
- package/output/app/lifecycle.test.js +0 -152
- package/output/app/middleware/auth.d.ts +0 -71
- package/output/app/middleware/auth.d.ts.map +0 -1
- package/output/app/middleware/auth.js +0 -190
- package/output/app/middleware/context.d.ts +0 -13
- package/output/app/middleware/context.d.ts.map +0 -1
- package/output/app/middleware/context.js +0 -15
- package/output/app/middleware/cors.d.ts +0 -14
- package/output/app/middleware/cors.d.ts.map +0 -1
- package/output/app/middleware/cors.js +0 -30
- package/output/app/middleware/index.d.ts +0 -17
- package/output/app/middleware/index.d.ts.map +0 -1
- package/output/app/middleware/index.js +0 -16
- package/output/app/middleware/rate-limit.d.ts +0 -24
- package/output/app/middleware/rate-limit.d.ts.map +0 -1
- package/output/app/middleware/rate-limit.js +0 -46
- package/output/app/middleware-order.test.d.ts +0 -2
- package/output/app/middleware-order.test.d.ts.map +0 -1
- package/output/app/middleware-order.test.js +0 -148
- package/output/app/permission-operations.d.ts +0 -48
- package/output/app/permission-operations.d.ts.map +0 -1
- package/output/app/permission-operations.js +0 -77
- package/output/app/permission-operations.test.d.ts +0 -2
- package/output/app/permission-operations.test.d.ts.map +0 -1
- package/output/app/permission-operations.test.js +0 -72
- package/output/app/permission-registration.test.d.ts +0 -2
- package/output/app/permission-registration.test.d.ts.map +0 -1
- package/output/app/permission-registration.test.js +0 -138
- package/output/app/redis.d.ts.map +0 -1
- package/output/app/registered-operations.test.d.ts +0 -2
- package/output/app/registered-operations.test.d.ts.map +0 -1
- package/output/app/registered-operations.test.js +0 -57
- package/output/app/request-id.test.d.ts +0 -2
- package/output/app/request-id.test.d.ts.map +0 -1
- package/output/app/request-id.test.js +0 -130
- package/output/app/resources.test.d.ts +0 -2
- package/output/app/resources.test.d.ts.map +0 -1
- package/output/app/resources.test.js +0 -199
- package/output/app/shutdown.d.ts +0 -22
- package/output/app/shutdown.d.ts.map +0 -1
- package/output/app/shutdown.js +0 -30
- package/output/app/shutdown.test.d.ts +0 -2
- package/output/app/shutdown.test.d.ts.map +0 -1
- package/output/app/shutdown.test.js +0 -103
- package/output/app/signal.d.ts +0 -12
- package/output/app/signal.d.ts.map +0 -1
- package/output/app/smoke.test.d.ts +0 -2
- package/output/app/smoke.test.d.ts.map +0 -1
- package/output/app/smoke.test.js +0 -210
- package/output/app/test-support.d.ts +0 -21
- package/output/app/test-support.d.ts.map +0 -1
- package/output/app/test-support.js +0 -24
- package/output/app/type-augment.d.ts.map +0 -1
- package/output/app/types.d.ts +0 -228
- package/output/app/types.d.ts.map +0 -1
- package/output/context/index.d.ts +0 -6
- package/output/context/index.d.ts.map +0 -1
- package/output/context/index.js +0 -14
- package/output/rate-limiter/index.d.ts +0 -5
- package/output/rate-limiter/index.d.ts.map +0 -1
- package/output/rate-limiter/index.js +0 -4
- package/output/rate-limiter/memory-store.d.ts.map +0 -1
- package/output/rate-limiter/rate-limiter.d.ts.map +0 -1
- package/output/rate-limiter/redis-store.d.ts.map +0 -1
- package/output/rate-limiter/redis-store.test.d.ts.map +0 -1
- package/output/rate-limiter/types.d.ts.map +0 -1
- package/output/redis-cache/index.d.ts +0 -4
- package/output/redis-cache/index.d.ts.map +0 -1
- package/output/redis-cache/index.js +0 -1
- package/output/redis-cache/redis-cache.d.ts.map +0 -1
- package/output/redis-cache/redis-cache.test.d.ts +0 -2
- package/output/redis-cache/redis-cache.test.d.ts.map +0 -1
- package/output/schema/index.d.ts.map +0 -1
- /package/output/{app → core}/env.test.d.ts +0 -0
- /package/output/{rate-limiter → core/modules/auth-provider}/types.js +0 -0
- /package/output/{context → core/modules/context}/index.test.d.ts +0 -0
- /package/output/{context → core/modules/context}/index.test.js +0 -0
- /package/output/{app → core}/type-augment.js +0 -0
- /package/output/{app → core}/types.js +0 -0
- /package/output/{rate-limiter/rate-limiter.js → rate-limit/limiter.js} +0 -0
- /package/output/{rate-limiter → rate-limit}/memory-store.d.ts +0 -0
- /package/output/{rate-limiter → rate-limit}/memory-store.js +0 -0
- /package/output/{rate-limiter → rate-limit}/redis-store.d.ts +0 -0
- /package/output/{rate-limiter → rate-limit}/redis-store.js +0 -0
- /package/output/{rate-limiter → rate-limit}/redis-store.test.d.ts +0 -0
- /package/output/{redis-cache/redis-cache.js → redis/cache.js} +0 -0
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
2
|
-
import { defineServer, generateOpenApi, startServer } from './entries.js';
|
|
3
|
-
import { SystemError, UserError } from './errors.js';
|
|
4
|
-
const rows = { 'server.domain': 'example.com' };
|
|
5
|
-
const fakeDatabase = {
|
|
6
|
-
get: (key) => Promise.resolve(rows[key]),
|
|
7
|
-
};
|
|
8
|
-
describe('config 槽位(N1 §2 / N2 §2.4)', () => {
|
|
9
|
-
it('① 入参含 env/log/resources,且不含 config/services/app', async () => {
|
|
10
|
-
const captured = [];
|
|
11
|
-
const server = defineServer({
|
|
12
|
-
app: { service: 'config-test', title: 'Config Test', version: '1.0.0' },
|
|
13
|
-
resources: () => ({ database: fakeDatabase }),
|
|
14
|
-
config: (ctx) => {
|
|
15
|
-
captured.push(ctx);
|
|
16
|
-
return { domain: 'example.com' };
|
|
17
|
-
},
|
|
18
|
-
services: () => ({}),
|
|
19
|
-
middlewares: () => [],
|
|
20
|
-
routers: () => undefined,
|
|
21
|
-
});
|
|
22
|
-
const app = await startServer(server, { listen: false });
|
|
23
|
-
try {
|
|
24
|
-
expect(captured).toHaveLength(1);
|
|
25
|
-
const ctx = captured[0];
|
|
26
|
-
expect('config' in ctx).toBe(false);
|
|
27
|
-
expect('services' in ctx).toBe(false);
|
|
28
|
-
expect('app' in ctx).toBe(false);
|
|
29
|
-
expect(ctx.resources.database).toBe(fakeDatabase);
|
|
30
|
-
expect(typeof ctx.log.info).toBe('function');
|
|
31
|
-
expect(Object.keys(ctx.env).sort()).toEqual([
|
|
32
|
-
'API_PORT',
|
|
33
|
-
'DATABASE_URL',
|
|
34
|
-
'ENV',
|
|
35
|
-
'LOG_LEVEL',
|
|
36
|
-
'REDIS_URL',
|
|
37
|
-
]);
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
await app.close();
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
it('② 可从「库」读配置:`services` / `middlewares` 经 `ctx.config` 拿到值', async () => {
|
|
44
|
-
let domainInServices;
|
|
45
|
-
let domainInMiddlewares;
|
|
46
|
-
const server = defineServer({
|
|
47
|
-
app: { service: 'config-from-database', title: 'Config From Database', version: '1.0.0' },
|
|
48
|
-
resources: () => ({ database: fakeDatabase }),
|
|
49
|
-
config: async (ctx) => ({ domain: (await ctx.resources.database.get('server.domain')) ?? '' }),
|
|
50
|
-
services: (ctx) => {
|
|
51
|
-
domainInServices = ctx.config.domain;
|
|
52
|
-
return {};
|
|
53
|
-
},
|
|
54
|
-
middlewares: (ctx) => {
|
|
55
|
-
domainInMiddlewares = ctx.config.domain;
|
|
56
|
-
return [];
|
|
57
|
-
},
|
|
58
|
-
routers: (ctx) => {
|
|
59
|
-
ctx.app.get('/domain', () => ({ domain: ctx.services === null ? '' : 'ok' }));
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
const app = await startServer(server, { listen: false });
|
|
63
|
-
try {
|
|
64
|
-
expect(domainInServices).toBe('example.com');
|
|
65
|
-
expect(domainInMiddlewares).toBe('example.com');
|
|
66
|
-
}
|
|
67
|
-
finally {
|
|
68
|
-
await app.close();
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
it('③ 同一份定义:startServer 跑 config,generateOpenApi 不跑(红线)', async () => {
|
|
72
|
-
let calls = 0;
|
|
73
|
-
const server = defineServer({
|
|
74
|
-
app: { service: 'config-redline', title: 'Config Red Line', version: '1.0.0' },
|
|
75
|
-
resources: () => ({ database: fakeDatabase }),
|
|
76
|
-
config: () => {
|
|
77
|
-
calls += 1;
|
|
78
|
-
return {};
|
|
79
|
-
},
|
|
80
|
-
services: () => ({}),
|
|
81
|
-
middlewares: () => [],
|
|
82
|
-
routers: () => undefined,
|
|
83
|
-
});
|
|
84
|
-
await generateOpenApi(server);
|
|
85
|
-
expect(calls).toBe(0);
|
|
86
|
-
const app = await startServer(server, { listen: false });
|
|
87
|
-
expect(calls).toBe(1);
|
|
88
|
-
await app.close();
|
|
89
|
-
});
|
|
90
|
-
it('④ 出 spec 路径:services 读 ctx.config 抛 CONFIG_UNAVAILABLE(构造期不得读配置)', async () => {
|
|
91
|
-
const server = defineServer({
|
|
92
|
-
app: { service: 'config-openapi', title: 'Config OpenApi', version: '1.0.0' },
|
|
93
|
-
resources: () => ({}),
|
|
94
|
-
config: () => ({ domain: 'spec' }),
|
|
95
|
-
services: (ctx) => {
|
|
96
|
-
// 构造期不得读配置;出 spec 路径上读到即抛
|
|
97
|
-
void ctx.config;
|
|
98
|
-
return {};
|
|
99
|
-
},
|
|
100
|
-
middlewares: () => [],
|
|
101
|
-
routers: () => undefined,
|
|
102
|
-
});
|
|
103
|
-
let caught;
|
|
104
|
-
try {
|
|
105
|
-
await generateOpenApi(server);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
caught = error;
|
|
109
|
-
}
|
|
110
|
-
expect(SystemError.is(caught)).toBe(true);
|
|
111
|
-
expect(caught.type).toBe('CONFIG_UNAVAILABLE');
|
|
112
|
-
});
|
|
113
|
-
it('⑤ `UserError` / `SystemError` 的 `status` 是字面量、`is()` 走品牌(N2 §2.12)', () => {
|
|
114
|
-
const user = new UserError('INVALID_TOKEN', undefined, 'boom');
|
|
115
|
-
const system = new SystemError('DATABASE_ERROR', undefined, 'boom');
|
|
116
|
-
// `status` 是字面量类型(改错直接编译失败)
|
|
117
|
-
expectTypeOf(user.status).toEqualTypeOf();
|
|
118
|
-
expectTypeOf(system.status).toEqualTypeOf();
|
|
119
|
-
expect(user.type).toBe('INVALID_TOKEN');
|
|
120
|
-
expect(user.status).toBe(400);
|
|
121
|
-
expect(system.status).toBe(500);
|
|
122
|
-
// `is()` 走 `Symbol.for` 品牌:**不用 `instanceof`**,原型链丢失也能识别
|
|
123
|
-
const plainUserError = Object.assign(Object.create(null), {
|
|
124
|
-
type: 'INVALID_TOKEN',
|
|
125
|
-
message: 'boom',
|
|
126
|
-
});
|
|
127
|
-
Object.defineProperty(plainUserError, Symbol.for('@taicode/common/UserError'), { value: true });
|
|
128
|
-
expect(UserError.is(plainUserError)).toBe(true);
|
|
129
|
-
expect(SystemError.is(plainUserError)).toBe(false);
|
|
130
|
-
expect(UserError.is(new Error('boom'))).toBe(false);
|
|
131
|
-
});
|
|
132
|
-
});
|
package/output/app/context.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { Disposer } from '@taicode/common-base';
|
|
2
|
-
import type { ConfigEnv } from './env.js';
|
|
3
|
-
import type { AppInstance, ConfigContext, ErrorClassifier, LoggerLike, MiddlewareContext, ResourcesContext, ResourcesView, RouterContext, ServiceContext, ShutdownContext } from './types.js';
|
|
4
|
-
/**
|
|
5
|
-
* 分阶段 ctx 的运行时构造(N1 §2)。
|
|
6
|
-
*
|
|
7
|
-
* 每个槽位拿到的是**字段最小集合**的普通对象;`config` 用 getter 暴露,出 spec 路径
|
|
8
|
-
* (`generateOpenApi` 不跑 `config` 槽位)读到它时抛 `SystemError('CONFIG_UNAVAILABLE')`
|
|
9
|
-
* —— 让「构造期不得读配置」有运行期护栏,而不仅是文档规则。
|
|
10
|
-
*/
|
|
11
|
-
/** 运行时镜像 `Live<T>`:剔除值为 `false` 的键(编译期静态关闭) */
|
|
12
|
-
export declare function liveResources(resources: object): Record<string, unknown>;
|
|
13
|
-
/** `config` 槽位产物持有者(`startServer` 路径写入;出 spec 路径留空) */
|
|
14
|
-
export interface ConfigHolder<C> {
|
|
15
|
-
current: Awaited<C> | undefined;
|
|
16
|
-
}
|
|
17
|
-
export declare function createConfigHolder<C>(): ConfigHolder<C>;
|
|
18
|
-
/** 读配置:react 未就绪时抛 `SystemError('CONFIG_UNAVAILABLE')` */
|
|
19
|
-
export declare function requireConfig<C>(holder: ConfigHolder<C>): Awaited<C>;
|
|
20
|
-
/** 按**已知键**从配置值里取字段(框架内置单元消费配置的单一入口;不做形状校验) */
|
|
21
|
-
export declare function readConfigKey(config: unknown, key: string): unknown;
|
|
22
|
-
/** `resources(ctx)` 入参 */
|
|
23
|
-
export interface ResourcesContextParams {
|
|
24
|
-
env: ConfigEnv;
|
|
25
|
-
log: LoggerLike;
|
|
26
|
-
/** 收集器:`bootServer` 注入,把各资源注册的分类器按注册顺序收起来 */
|
|
27
|
-
registerClassifyError: (classifier: ErrorClassifier) => void;
|
|
28
|
-
}
|
|
29
|
-
export declare function createResourcesContext(params: ResourcesContextParams): ResourcesContext;
|
|
30
|
-
/** `config(ctx)` 入参 */
|
|
31
|
-
export interface ConfigContextParams<R> {
|
|
32
|
-
env: ConfigEnv;
|
|
33
|
-
log: LoggerLike;
|
|
34
|
-
resources: ResourcesView<R>;
|
|
35
|
-
}
|
|
36
|
-
export declare function createConfigContext<R>(params: ConfigContextParams<R>): ConfigContext<R>;
|
|
37
|
-
/** `services(ctx)` 入参 */
|
|
38
|
-
export interface ServiceContextParams<R, C> {
|
|
39
|
-
log: LoggerLike;
|
|
40
|
-
disposer: Disposer;
|
|
41
|
-
resources: ResourcesView<R>;
|
|
42
|
-
holder: ConfigHolder<C>;
|
|
43
|
-
}
|
|
44
|
-
export declare function createServiceContext<R, C>(params: ServiceContextParams<R, C>): ServiceContext<R, C>;
|
|
45
|
-
/** `middlewares(ctx)` 入参 */
|
|
46
|
-
export interface MiddlewareContextParams<C, S> {
|
|
47
|
-
app: AppInstance;
|
|
48
|
-
log: LoggerLike;
|
|
49
|
-
services: Awaited<S>;
|
|
50
|
-
holder: ConfigHolder<C>;
|
|
51
|
-
}
|
|
52
|
-
export declare function createMiddlewareContext<C, S>(params: MiddlewareContextParams<C, S>): MiddlewareContext<C, S>;
|
|
53
|
-
/** `routers(ctx)` 入参 */
|
|
54
|
-
export interface RouterContextParams<S> {
|
|
55
|
-
app: AppInstance;
|
|
56
|
-
log: LoggerLike;
|
|
57
|
-
services: Awaited<S>;
|
|
58
|
-
}
|
|
59
|
-
export declare function createRouterContext<S>(params: RouterContextParams<S>): RouterContext<S>;
|
|
60
|
-
/** 关闭阶段视图入参 */
|
|
61
|
-
export interface ShutdownContextParams<R, C, S> {
|
|
62
|
-
app: AppInstance;
|
|
63
|
-
log: LoggerLike;
|
|
64
|
-
disposer: Disposer;
|
|
65
|
-
resources: ResourcesView<R>;
|
|
66
|
-
holder: ConfigHolder<C>;
|
|
67
|
-
services: Awaited<S>;
|
|
68
|
-
}
|
|
69
|
-
export declare function createShutdownContext<R, C, S>(params: ShutdownContextParams<R, C, S>): ShutdownContext<R, C, S>;
|
|
70
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../source/app/context.ts"],"names":[],"mappings":"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"}
|
package/output/app/context.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { SystemError } from './errors.js';
|
|
2
|
-
/**
|
|
3
|
-
* 分阶段 ctx 的运行时构造(N1 §2)。
|
|
4
|
-
*
|
|
5
|
-
* 每个槽位拿到的是**字段最小集合**的普通对象;`config` 用 getter 暴露,出 spec 路径
|
|
6
|
-
* (`generateOpenApi` 不跑 `config` 槽位)读到它时抛 `SystemError('CONFIG_UNAVAILABLE')`
|
|
7
|
-
* —— 让「构造期不得读配置」有运行期护栏,而不仅是文档规则。
|
|
8
|
-
*/
|
|
9
|
-
/** 运行时镜像 `Live<T>`:剔除值为 `false` 的键(编译期静态关闭) */
|
|
10
|
-
export function liveResources(resources) {
|
|
11
|
-
const result = {};
|
|
12
|
-
for (const [key, value] of Object.entries(resources)) {
|
|
13
|
-
if (value !== false) {
|
|
14
|
-
result[key] = value;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
export function createConfigHolder() {
|
|
20
|
-
return { current: undefined };
|
|
21
|
-
}
|
|
22
|
-
/** 读配置:react 未就绪时抛 `SystemError('CONFIG_UNAVAILABLE')` */
|
|
23
|
-
export function requireConfig(holder) {
|
|
24
|
-
if (holder.current === undefined) {
|
|
25
|
-
throw new SystemError('CONFIG_UNAVAILABLE', undefined, '配置尚未就绪(generateOpenApi 路径不跑 config 槽位):任何单元不得在构造期读配置');
|
|
26
|
-
}
|
|
27
|
-
return holder.current;
|
|
28
|
-
}
|
|
29
|
-
/** 按**已知键**从配置值里取字段(框架内置单元消费配置的单一入口;不做形状校验) */
|
|
30
|
-
export function readConfigKey(config, key) {
|
|
31
|
-
return config?.[key];
|
|
32
|
-
}
|
|
33
|
-
export function createResourcesContext(params) {
|
|
34
|
-
return { env: params.env, log: params.log, registerClassifyError: params.registerClassifyError };
|
|
35
|
-
}
|
|
36
|
-
export function createConfigContext(params) {
|
|
37
|
-
return { env: params.env, log: params.log, resources: params.resources };
|
|
38
|
-
}
|
|
39
|
-
export function createServiceContext(params) {
|
|
40
|
-
return {
|
|
41
|
-
log: params.log,
|
|
42
|
-
disposer: params.disposer,
|
|
43
|
-
resources: params.resources,
|
|
44
|
-
get config() {
|
|
45
|
-
return requireConfig(params.holder);
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export function createMiddlewareContext(params) {
|
|
50
|
-
return {
|
|
51
|
-
app: params.app,
|
|
52
|
-
log: params.log,
|
|
53
|
-
services: params.services,
|
|
54
|
-
get config() {
|
|
55
|
-
return requireConfig(params.holder);
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export function createRouterContext(params) {
|
|
60
|
-
return { app: params.app, log: params.log, services: params.services };
|
|
61
|
-
}
|
|
62
|
-
export function createShutdownContext(params) {
|
|
63
|
-
return {
|
|
64
|
-
app: params.app,
|
|
65
|
-
log: params.log,
|
|
66
|
-
disposer: params.disposer,
|
|
67
|
-
resources: params.resources,
|
|
68
|
-
get config() {
|
|
69
|
-
return requireConfig(params.holder);
|
|
70
|
-
},
|
|
71
|
-
services: params.services,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ConfigEnv } from '../env.js';
|
|
2
|
-
import type { FastifyInstance } from 'fastify';
|
|
3
|
-
/**
|
|
4
|
-
* core `cookie`(设计 §5.1)——**框架内置、锁定、不可替换/修改**。
|
|
5
|
-
*
|
|
6
|
-
* `@fastify/cookie`;cookie 名 / domain 从 `ctx.readConfig('server')` 取(**请求期惰性现读**,刷新后即生效);
|
|
7
|
-
* 显式设 `sameSite`(默认 `lax`)与 `secure`(默认 `ENV === 'production'`);注册在 `auth` 之前
|
|
8
|
-
* (框架内置序),故 `auth` 读 cookie 无需用户保证。
|
|
9
|
-
*/
|
|
10
|
-
export interface AuthCookieOptions {
|
|
11
|
-
maxAge?: number;
|
|
12
|
-
path?: string;
|
|
13
|
-
domain?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface CookieCoreOptions {
|
|
16
|
-
env: ConfigEnv;
|
|
17
|
-
/** 取最新配置中某个键的访问器(**每次调用现读**,不得缓存返回值) */
|
|
18
|
-
readConfig: (key: string) => unknown;
|
|
19
|
-
}
|
|
20
|
-
/** 从 `readConfig('server')` 的返回值读取 cookie 名列表(缺省 `['token']`,对齐四家现状) */
|
|
21
|
-
export declare function resolveCookieNames(server: unknown): string[];
|
|
22
|
-
/** 从 `readConfig('server')` 的返回值读取 cookie domain */
|
|
23
|
-
export declare function resolveCookieDomain(server: unknown): string | undefined;
|
|
24
|
-
export declare function registerCookie(app: FastifyInstance, options: CookieCoreOptions): void;
|
|
25
|
-
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../source/app/core/cookie.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,SAAS,CAAA;AAE5D;;;;;;GAMG;AAEH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAOD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAA;IACd,wCAAwC;IACxC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CACrC;AAED,wEAAwE;AACxE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAG5D;AAED,oDAAoD;AACpD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEvE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAerF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AppIdentity } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* 身份块在 `app` 上的存放键(Symbol,**不进公共契约**)。
|
|
4
|
-
*
|
|
5
|
-
* `defineServer({ app })` 的身份块只属于定义产物;`middlewares` / `routers` 的 ctx 里没有它
|
|
6
|
-
* (可见性按需收窄),框架内置单元(`auth` 权限自注册 / `rateLimit` 前缀)需要 `service` /
|
|
7
|
-
* `version` 时从这里读。
|
|
8
|
-
*/
|
|
9
|
-
export declare const SERVER_IDENTITY: unique symbol;
|
|
10
|
-
export declare function attachServerIdentity(app: unknown, identity: AppIdentity): void;
|
|
11
|
-
export declare function readServerIdentity(app: unknown): AppIdentity | undefined;
|
|
12
|
-
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../source/app/core/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,eAAwC,CAAA;AAEpE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,CAE9E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAExE"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ErrorClassifier } from './response.js';
|
|
2
|
-
import type { ConfigEnv } from '../env.js';
|
|
3
|
-
import type { AppIdentity } from '../types.js';
|
|
4
|
-
import type { FastifyInstance } from 'fastify';
|
|
5
|
-
export { registerCookie, resolveCookieNames, resolveCookieDomain } from './cookie.js';
|
|
6
|
-
export { registerResponse, createSuccessResponse, createErrorResponse } from './response.js';
|
|
7
|
-
export { registerOpenApi, DOC_ROUTE_PREFIX, DOC_SPEC_ROUTE } from './openapi.js';
|
|
8
|
-
export { registerRequestId, REQUEST_ID_HEADER, REQUEST_ID_LOG_LABEL } from './request-id.js';
|
|
9
|
-
export { createLoggerOptions, LOG_REDACT_PATHS } from './logging.js';
|
|
10
|
-
export { SERVER_IDENTITY, attachServerIdentity, readServerIdentity } from './identity.js';
|
|
11
|
-
export type { AuthCookieOptions, CookieCoreOptions } from './cookie.js';
|
|
12
|
-
export type { ResponseCoreOptions, ResponseEnvelope, ErrorClassifier } from './response.js';
|
|
13
|
-
export type { OpenApiCoreOptions } from './openapi.js';
|
|
14
|
-
/**
|
|
15
|
-
* core `schema`(设计 §5.1)——**框架内置、锁定、不可替换/修改**。
|
|
16
|
-
*
|
|
17
|
-
* 装配 `fastify-type-provider-zod` 的 validator / serializer compiler;响应 schema 由框架统一
|
|
18
|
-
* 生成(业务侧用 `../schema/index.js` 的 `responseSchema`)。
|
|
19
|
-
*/
|
|
20
|
-
export declare function registerSchema(app: FastifyInstance): void;
|
|
21
|
-
/**
|
|
22
|
-
* core 步骤 `createFastify`(`prepare`)。
|
|
23
|
-
*
|
|
24
|
-
* **总是**建 pino logger(level = `LOG_LEVEL`,默认 `info`) + 内置 `requestId`(入站 `x-request-id`
|
|
25
|
-
* 复用 / `randomUUID`,日志字段 `requestId`)。`trustProxy: true` 与四家现状一致。
|
|
26
|
-
*/
|
|
27
|
-
export declare function createFastify(env: ConfigEnv): FastifyInstance;
|
|
28
|
-
/** core 装配入参 */
|
|
29
|
-
export interface CoreRegistrationOptions {
|
|
30
|
-
/** 身份块(`service` / `title` / `version`):openapi + 内置单元从这里读 */
|
|
31
|
-
identity: AppIdentity;
|
|
32
|
-
env: ConfigEnv;
|
|
33
|
-
/** 资源错误分类(各资源经 `ctx.registerClassifyError` 注册;缺省 = 落 `UNKNOWN_ERROR`) */
|
|
34
|
-
classifyResourceError?: ErrorClassifier;
|
|
35
|
-
/** 取**已加载**配置中某个键的访问器(cookie domain 等**惰性**取值;不得在构造期调用) */
|
|
36
|
-
readConfig: (key: string) => unknown;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* core 装配:`schema` → `cookie` → `response` → `openapi` → 路由注册表。
|
|
40
|
-
* `requestId` 的响应回吐 hook 一并注册。**构造期不读配置**(`cookie` 的 domain 在请求期惰性读取),
|
|
41
|
-
* 故出 spec 路径(`readConfig` 不可用)不会触发。
|
|
42
|
-
*/
|
|
43
|
-
export declare function registerCore(app: FastifyInstance, options: CoreRegistrationOptions): Promise<void>;
|
|
44
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/app/core/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC5F,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEzF,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACvE,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC3F,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAMzD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,GAAG,eAAe,CAM7D;AAED,gBAAgB;AAChB,MAAM,WAAW,uBAAuB;IACtC,8DAA8D;IAC9D,QAAQ,EAAE,WAAW,CAAA;IACrB,GAAG,EAAE,SAAS,CAAA;IACd,yEAAyE;IACzE,qBAAqB,CAAC,EAAE,eAAe,CAAA;IACvC,2DAA2D;IAC3D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CACrC;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAaxG"}
|
package/output/app/core/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import Fastify from 'fastify';
|
|
2
|
-
import { serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod';
|
|
3
|
-
import { installRegisteredOperations } from '../permission-operations.js';
|
|
4
|
-
import { registerCookie } from './cookie.js';
|
|
5
|
-
import { attachServerIdentity } from './identity.js';
|
|
6
|
-
import { createLoggerOptions } from './logging.js';
|
|
7
|
-
import { registerOpenApi } from './openapi.js';
|
|
8
|
-
import { createRequestIdOptions, registerRequestId } from './request-id.js';
|
|
9
|
-
import { registerResponse } from './response.js';
|
|
10
|
-
export { registerCookie, resolveCookieNames, resolveCookieDomain } from './cookie.js';
|
|
11
|
-
export { registerResponse, createSuccessResponse, createErrorResponse } from './response.js';
|
|
12
|
-
export { registerOpenApi, DOC_ROUTE_PREFIX, DOC_SPEC_ROUTE } from './openapi.js';
|
|
13
|
-
export { registerRequestId, REQUEST_ID_HEADER, REQUEST_ID_LOG_LABEL } from './request-id.js';
|
|
14
|
-
export { createLoggerOptions, LOG_REDACT_PATHS } from './logging.js';
|
|
15
|
-
export { SERVER_IDENTITY, attachServerIdentity, readServerIdentity } from './identity.js';
|
|
16
|
-
/**
|
|
17
|
-
* core `schema`(设计 §5.1)——**框架内置、锁定、不可替换/修改**。
|
|
18
|
-
*
|
|
19
|
-
* 装配 `fastify-type-provider-zod` 的 validator / serializer compiler;响应 schema 由框架统一
|
|
20
|
-
* 生成(业务侧用 `../schema/index.js` 的 `responseSchema`)。
|
|
21
|
-
*/
|
|
22
|
-
export function registerSchema(app) {
|
|
23
|
-
app.setValidatorCompiler(validatorCompiler);
|
|
24
|
-
app.setSerializerCompiler(serializerCompiler);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* core 步骤 `createFastify`(`prepare`)。
|
|
28
|
-
*
|
|
29
|
-
* **总是**建 pino logger(level = `LOG_LEVEL`,默认 `info`) + 内置 `requestId`(入站 `x-request-id`
|
|
30
|
-
* 复用 / `randomUUID`,日志字段 `requestId`)。`trustProxy: true` 与四家现状一致。
|
|
31
|
-
*/
|
|
32
|
-
export function createFastify(env) {
|
|
33
|
-
return Fastify({
|
|
34
|
-
trustProxy: true,
|
|
35
|
-
logger: createLoggerOptions(env),
|
|
36
|
-
...createRequestIdOptions(),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* core 装配:`schema` → `cookie` → `response` → `openapi` → 路由注册表。
|
|
41
|
-
* `requestId` 的响应回吐 hook 一并注册。**构造期不读配置**(`cookie` 的 domain 在请求期惰性读取),
|
|
42
|
-
* 故出 spec 路径(`readConfig` 不可用)不会触发。
|
|
43
|
-
*/
|
|
44
|
-
export async function registerCore(app, options) {
|
|
45
|
-
attachServerIdentity(app, options.identity);
|
|
46
|
-
registerSchema(app); // schema → zod compiler
|
|
47
|
-
registerCookie(app, { env: options.env, readConfig: options.readConfig });
|
|
48
|
-
registerResponse(app, { classifyResourceError: options.classifyResourceError });
|
|
49
|
-
// await:确定性冲刷插件队列,保证 swagger 的 root `onRoute` 钩子在路由注册之前就位
|
|
50
|
-
await registerOpenApi(app, {
|
|
51
|
-
title: options.identity.title,
|
|
52
|
-
version: options.identity.version,
|
|
53
|
-
});
|
|
54
|
-
// 路由注册表:在 routers 阶段之前挂 root `onRoute`,供 `auth` 权限自注册读取(与 swagger 解耦)
|
|
55
|
-
installRegisteredOperations(app);
|
|
56
|
-
registerRequestId(app); // 响应回吐 x-request-id
|
|
57
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ConfigEnv } from '../env.js';
|
|
2
|
-
import type { FastifyServerOptions } from 'fastify';
|
|
3
|
-
/**
|
|
4
|
-
* core `logging`(设计 §5.1)——**框架内置、锁定、不可替换/修改**。
|
|
5
|
-
*
|
|
6
|
-
* `createFastify` **总是**建 pino logger(级别取 `LOG_LEVEL`,默认 `info`);原 `logging: false`
|
|
7
|
-
* 开关随 `CoreOptions` 一并删除,日志始终开启,不再由 `debug` 控制。
|
|
8
|
-
*/
|
|
9
|
-
/** 默认 `redact` 路径(设计 §5.1) */
|
|
10
|
-
export declare const LOG_REDACT_PATHS: readonly ["authorization", "cookie", "set-cookie", "req.headers.authorization", "req.headers.cookie", "*.token", "*.password", "*.secretKey", "*.secretValue"];
|
|
11
|
-
/** 构造 Fastify 的 logger 选项 */
|
|
12
|
-
export declare function createLoggerOptions(env: ConfigEnv): FastifyServerOptions['logger'];
|
|
13
|
-
//# sourceMappingURL=logging.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../../source/app/core/logging.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD;;;;;GAKG;AAEH,8BAA8B;AAC9B,eAAO,MAAM,gBAAgB,gKAUnB,CAAA;AAEV,6BAA6B;AAC7B,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,SAAS,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAQlF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { FastifyInstance } from 'fastify';
|
|
2
|
-
/**
|
|
3
|
-
* core `openapi`(设计 §5.1)——**框架内置、锁定、不可替换/修改**。
|
|
4
|
-
*
|
|
5
|
-
* `@fastify/swagger` + `@scalar/fastify-api-reference`;`/reference` 与 `/reference/openapi.json`;
|
|
6
|
-
* `servers: [{ url: '/' }]`(构建期不依赖 env / DB);`version` 取 `app.version`(必填,无默认);
|
|
7
|
-
* `securitySchemes.bearerAuth`;`onListen` 打印实际地址。
|
|
8
|
-
*/
|
|
9
|
-
export declare const DOC_ROUTE_PREFIX = "/reference";
|
|
10
|
-
export declare const DOC_SPEC_ROUTE = "/reference/openapi.json";
|
|
11
|
-
export declare const OPENAPI_SPEC_VERSION = "3.0.3";
|
|
12
|
-
export interface OpenApiCoreOptions {
|
|
13
|
-
title: string;
|
|
14
|
-
version: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function registerOpenApi(app: FastifyInstance, options: OpenApiCoreOptions): Promise<void>;
|
|
17
|
-
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../source/app/core/openapi.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C;;;;;;GAMG;AAEH,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAC5C,eAAO,MAAM,cAAc,4BAA4B,CAAA;AACvD,eAAO,MAAM,oBAAoB,UAAU,CAAA;AAE3C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BtG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-id.d.ts","sourceRoot":"","sources":["../../../source/app/core/request-id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,iBAAiB,iBAAiB,CAAA;AAC/C,eAAO,MAAM,oBAAoB,cAAc,CAAA;AAE/C,qEAAqE;AACrE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAOpG;AAED,sCAAsC;AACtC,wBAAgB,sBAAsB,IAAI;IACxC,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;KAAE,KAAK,MAAM,CAAA;CAC1F,CAOA;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAwB5D"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { FastifyInstance } from 'fastify';
|
|
2
|
-
import type { ErrorClassifier } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* core `response`(设计 §5.1 / §8,错误契约 D7)——**框架内置、锁定、不可替换/修改**。
|
|
5
|
-
*
|
|
6
|
-
* - 成功信封 `{ status: 'SUCCESS', message: 'ok', data }`(由 `preSerialization` 统一包裹)。
|
|
7
|
-
* - 错误信封 `{ status: <错误码字符串>, message, data: null }`。
|
|
8
|
-
* - `setErrorHandler` 固定分支:`UserError`→400(`error.status` 字面量)/ `SystemError`→500 /
|
|
9
|
-
* zod→400 / serde→500 / 资源(各资源 `ctx.registerClassifyError` 注册的分类器)→500 / 未知→500;**禁止按 `error.type` 细分**。
|
|
10
|
-
* - `setNotFoundHandler` → 404 + `NOT_IMPLEMENTED`(落 `warn`,文案对齐 expense/notice)。
|
|
11
|
-
* - 错误日志分级:`UserError` / zod → `warn`,其余 → `error`(带 stack)。
|
|
12
|
-
* - **错误只给稳定码**(`status` 放错误码字符串),文案不归框架(由前端 / i18n 决定,§10-6)。
|
|
13
|
-
*/
|
|
14
|
-
export declare const SUCCESS_STATUS = "SUCCESS";
|
|
15
|
-
export declare const NOT_IMPLEMENTED_STATUS = "NOT_IMPLEMENTED";
|
|
16
|
-
export declare const INVALID_INPUT_STATUS = "INVALID_INPUT";
|
|
17
|
-
export declare const SERIALIZATION_ERROR_STATUS = "RESPONSE_SERIALIZATION_ERROR";
|
|
18
|
-
export declare const UNKNOWN_ERROR_STATUS = "UNKNOWN_ERROR";
|
|
19
|
-
/** 通用兜底文案(仅在 `error.message` 为空时使用) */
|
|
20
|
-
export declare const DEFAULT_USER_MESSAGE = "\u8BF7\u6C42\u5931\u8D25";
|
|
21
|
-
export declare const DEFAULT_SYSTEM_MESSAGE = "\u7CFB\u7EDF\u9519\u8BEF";
|
|
22
|
-
export interface ResponseEnvelope<T> {
|
|
23
|
-
status: string;
|
|
24
|
-
message: string;
|
|
25
|
-
data: T;
|
|
26
|
-
}
|
|
27
|
-
export declare function createSuccessResponse<T>(data: T): ResponseEnvelope<T>;
|
|
28
|
-
export declare function createErrorResponse(status: string, message: string): ResponseEnvelope<null>;
|
|
29
|
-
/**
|
|
30
|
-
* 资源错误分类器(单一来源:`types.ts`)。
|
|
31
|
-
*
|
|
32
|
-
* **每个资源注册自己的分类器**(一个资源一个,各管各的错误域);由服务仓在 `resources(ctx)` 里
|
|
33
|
-
* 通过 `ctx.registerClassifyError` 注册;未注册时错误落 `UNKNOWN_ERROR` 兜底。
|
|
34
|
-
*/
|
|
35
|
-
export type { ErrorClassifier };
|
|
36
|
-
export interface ResponseCoreOptions {
|
|
37
|
-
/** 资源错误分类(各资源经 `ctx.registerClassifyError` 注册;缺省 = 不做资源错误分类) */
|
|
38
|
-
classifyResourceError?: ErrorClassifier;
|
|
39
|
-
}
|
|
40
|
-
export declare function registerResponse(app: FastifyInstance, options?: ResponseCoreOptions): void;
|
|
41
|
-
//# sourceMappingURL=response.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../source/app/core/response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,cAAc,YAAY,CAAA;AACvC,eAAO,MAAM,sBAAsB,oBAAoB,CAAA;AACvD,eAAO,MAAM,oBAAoB,kBAAkB,CAAA;AACnD,eAAO,MAAM,0BAA0B,iCAAiC,CAAA;AACxE,eAAO,MAAM,oBAAoB,kBAAkB,CAAA;AAEnD,uCAAuC;AACvC,eAAO,MAAM,oBAAoB,6BAAS,CAAA;AAC1C,eAAO,MAAM,sBAAsB,6BAAS,CAAA;AAE5C,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,CAAC,CAAA;CACR;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAErE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAE3F;AAsBD;;;;;GAKG;AACH,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,qBAAqB,CAAC,EAAE,eAAe,CAAA;CACxC;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAyD9F"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { ServerConfig } from './types.js';
|
|
2
|
-
/** #1 `resources` 看不到 `config` */
|
|
3
|
-
export declare function resourcesCannotSeeConfig(): void;
|
|
4
|
-
/** #2 `resources` 看不到 `services` */
|
|
5
|
-
export declare function resourcesCannotSeeServices(): void;
|
|
6
|
-
/** #3 `config` 看不到 `services` */
|
|
7
|
-
export declare function configCannotSeeServices(): void;
|
|
8
|
-
/** #4 `services` 看不到 `services`(禁 service 互依) */
|
|
9
|
-
export declare function servicesCannotSeeServices(): void;
|
|
10
|
-
/** #5 `routers` 看不到 `resources`(禁绕层直连数据层) */
|
|
11
|
-
export declare function routersCannotSeeResources(): void;
|
|
12
|
-
/** #6 `routers` 看不到 `config` */
|
|
13
|
-
export declare function routersCannotSeeConfig(): void;
|
|
14
|
-
/** #7 service 值声明 `dependsOn` → 该值塌成 `never` */
|
|
15
|
-
export declare function serviceValueCannotDeclareDependsOn(): void;
|
|
16
|
-
/** #8 service 值是原始类型 → 被拒(防把配置塞进 services) */
|
|
17
|
-
export declare function serviceValueCannotBePrimitive(): void;
|
|
18
|
-
/** #9 `startServer` 只接受品牌产物,裸 `ServerConfig` 编译失败 */
|
|
19
|
-
export declare function startServerRejectsBareConfig(bare: ServerConfig<unknown, unknown, unknown>): void;
|
|
20
|
-
/** #10 `app.version` 必填 */
|
|
21
|
-
export declare function appVersionIsRequired(): void;
|
|
22
|
-
/** #11 `cache: false` 静态关闭:键被 `Live<>` 从资源视图剔除 */
|
|
23
|
-
export declare function staticallyDisabledResourceIsRemoved(): void;
|
|
24
|
-
/** #12 `config` 看不到 `app` */
|
|
25
|
-
export declare function configCannotSeeApp(): void;
|
|
26
|
-
/** #13 `middlewares` 看不到 `resources`(中间件禁直连数据层) */
|
|
27
|
-
export declare function middlewaresCannotSeeResources(): void;
|
|
28
|
-
/** #14 `middlewares` 看不到 `env` */
|
|
29
|
-
export declare function middlewaresCannotSeeEnv(): void;
|
|
30
|
-
/** #15 `services` 看不到 `env`(服务层禁读 env) */
|
|
31
|
-
export declare function servicesCannotSeeEnv(): void;
|
|
32
|
-
/** #16 `config` 看不到 `registerClassifyError`(resources 槽位专属能力) */
|
|
33
|
-
export declare function configCannotRegisterClassifyError(): void;
|
|
34
|
-
/** #17 `services` 看不到 `registerClassifyError`(resources 槽位专属能力) */
|
|
35
|
-
export declare function servicesCannotRegisterClassifyError(): void;
|
|
36
|
-
/** #18 `middlewares` 看不到 `registerClassifyError`(resources 槽位专属能力) */
|
|
37
|
-
export declare function middlewaresCannotRegisterClassifyError(): void;
|
|
38
|
-
/** #19 `routers` 看不到 `registerClassifyError`(resources 槽位专属能力) */
|
|
39
|
-
export declare function routersCannotRegisterClassifyError(): void;
|
|
40
|
-
//# sourceMappingURL=define-server.negative-cases.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"define-server.negative-cases.d.ts","sourceRoot":"","sources":["../../source/app/define-server.negative-cases.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAgB9C,kCAAkC;AAClC,wBAAgB,wBAAwB,IAAI,IAAI,CAU/C;AAED,oCAAoC;AACpC,wBAAgB,0BAA0B,IAAI,IAAI,CAUjD;AAED,iCAAiC;AACjC,wBAAgB,uBAAuB,IAAI,IAAI,CAa9C;AAED,iDAAiD;AACjD,wBAAgB,yBAAyB,IAAI,IAAI,CAahD;AAED,6CAA6C;AAC7C,wBAAgB,yBAAyB,IAAI,IAAI,CAYhD;AAED,gCAAgC;AAChC,wBAAgB,sBAAsB,IAAI,IAAI,CAY7C;AAED,gDAAgD;AAChD,wBAAgB,kCAAkC,IAAI,IAAI,CAUzD;AAED,8CAA8C;AAC9C,wBAAgB,6BAA6B,IAAI,IAAI,CAUpD;AAED,qDAAqD;AACrD,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,CAGhG;AAED,2BAA2B;AAC3B,wBAAgB,oBAAoB,IAAI,IAAI,CAU3C;AAED,kDAAkD;AAClD,wBAAgB,mCAAmC,IAAI,IAAI,CAa1D;AAED,6BAA6B;AAC7B,wBAAgB,kBAAkB,IAAI,IAAI,CAazC;AAED,mDAAmD;AACnD,wBAAgB,6BAA6B,IAAI,IAAI,CAapD;AAED,kCAAkC;AAClC,wBAAgB,uBAAuB,IAAI,IAAI,CAa9C;AAED,0CAA0C;AAC1C,wBAAgB,oBAAoB,IAAI,IAAI,CAa3C;AAED,iEAAiE;AACjE,wBAAgB,iCAAiC,IAAI,IAAI,CAaxD;AAED,mEAAmE;AACnE,wBAAgB,mCAAmC,IAAI,IAAI,CAa1D;AAED,sEAAsE;AACtE,wBAAgB,sCAAsC,IAAI,IAAI,CAa7D;AAED,kEAAkE;AAClE,wBAAgB,kCAAkC,IAAI,IAAI,CAYzD"}
|