@tbox.cn/app-provider-mock 0.4.0 → 0.6.0

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.
@@ -1,13 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "Mock 营销域实例配置",
4
- "type": "object",
5
- "properties": {
6
- "couponTitle": { "type": "string", "title": "券标题", "description": "列表/详情/资产同源", "default": "满 100 减 20 元券" },
7
- "couponValueCents": { "type": "integer", "minimum": 0, "title": "券面额(分)", "default": 2000 },
8
- "couponThresholdCents": { "type": "integer", "minimum": 0, "title": "券门槛(分)", "default": 10000 },
9
- "couponValidityDays": { "type": "integer", "minimum": 1, "maximum": 365, "title": "券有效期(天)", "default": 30 },
10
- "grouponEnabled": { "type": "boolean", "title": "团购演示项开关", "description": "关闭 = 优惠列表仅券", "default": true },
11
- "activityTitle": { "type": "string", "title": "活动标题", "default": "示例商场周年庆" }
12
- }
13
- }
@@ -1,12 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "Mock 导购域实例配置",
4
- "type": "object",
5
- "properties": {
6
- "extraShopName": { "type": "string", "title": "追加门店名", "description": "空串 = 不追加", "default": "" },
7
- "extraShopCategory": { "type": "string", "title": "追加门店类目", "default": "餐饮" },
8
- "extraShopFloor": { "type": "string", "enum": ["B1", "1 楼", "2 楼", "3 楼", "4 楼"], "title": "追加门店楼层", "default": "3 楼" },
9
- "extraShopUnit": { "type": "string", "title": "追加门店铺位号", "default": "304" },
10
- "extraShopOpen": { "type": "boolean", "title": "追加门店营业状态", "default": true }
11
- }
12
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Mock 实例配置快照(fail-soft 单源):provider-mock 全部 config 消费的唯一读取面。
3
- * - 只透出 defaults 键(构造性防死字段);defaults 键 ≡ 被消费键;
4
- * - 非法回退缺省:类型族不符 / NaN / intKeys 键非整数 / 空串(统一「空串 = 缺省」语义);
5
- * - intKeys 显式列举而非按 default 值推断(JS 中 30.0 === 30,推断式必误拒分式经纬度);
6
- * - schema 是表单引导非门禁——守卫在消费侧(五层浅合并由平台侧完成,本层零合并逻辑)。
7
- * 双锁测试(tests/config-schema.test.ts)保证 schema.properties ≡ DEFAULTS 键集与 default 值。
8
- */
9
- export type CfgDefaults = Readonly<Record<string, string | number | boolean>>;
10
-
11
- export function resolveConfig<T extends CfgDefaults>(
12
- raw: unknown,
13
- defaults: T,
14
- intKeys: readonly string[] = [],
15
- ): T {
16
- const src = raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : {};
17
- const out: Record<string, string | number | boolean> = {};
18
- for (const [key, fallback] of Object.entries(defaults)) {
19
- const value = src[key];
20
- const ok = typeof value === typeof fallback
21
- && (typeof value !== 'number' || (Number.isFinite(value) && (!intKeys.includes(key) || Number.isInteger(value))))
22
- && (typeof value !== 'string' || value !== '');
23
- out[key] = ok ? (value as string | number | boolean) : fallback;
24
- }
25
- return out as T;
26
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * config schema 双锁(供给面 ↔ 消费面一致性):
3
- * ① 键集双向锁(schema.properties ≡ DEFAULTS——死字段/漏字段一次全拦)
4
- * ② default 漂移锁(schema 表单缺省 ≡ 实现缺省——面板不改动时的运行时真值)
5
- * ③ 整数对偶锁(schema type:'integer' ⟺ INT_KEYS——消费点整数守卫与表单引导同源)
6
- * ④ manifest 分发面锁(17 槽 configSchema 引用齐全 + 文件随包存在 + 槽→域文件映射)
7
- * ⑤ 楼层白名单同值锁(shopping enum ≡ SHOPPING_FLOORS——消费点守卫与引导同源)
8
- */
9
- import { describe, expect, it } from 'vitest';
10
- import { existsSync, readFileSync } from 'node:fs';
11
- import path from 'node:path';
12
- import { fileURLToPath } from 'node:url';
13
- import { MEMBER_CFG_DEFAULTS, MEMBER_CFG_INT_KEYS } from '../src/server/member';
14
- import { PARKING_CFG_DEFAULTS, PARKING_CFG_INT_KEYS } from '../src/server/parking';
15
- import { PROMOTION_CFG_DEFAULTS, PROMOTION_CFG_INT_KEYS } from '../src/server/promotion';
16
- import { SHOPPING_CFG_DEFAULTS, SHOPPING_CFG_INT_KEYS, SHOPPING_FLOORS } from '../src/server/shopping';
17
- import { MALL_INFO_CFG_DEFAULTS, MALL_INFO_CFG_INT_KEYS } from '../src/server/mall-info';
18
-
19
- const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
20
-
21
- interface SchemaProperty { type?: string; default?: unknown; enum?: readonly string[] }
22
- interface SchemaFile { properties: Record<string, SchemaProperty> }
23
-
24
- interface DomainCase {
25
- name: string;
26
- file: string;
27
- defaults: Readonly<Record<string, string | number | boolean>>;
28
- intKeys: readonly string[];
29
- }
30
-
31
- const DOMAINS: readonly DomainCase[] = [
32
- { name: 'member', file: 'member.config.json', defaults: MEMBER_CFG_DEFAULTS, intKeys: MEMBER_CFG_INT_KEYS },
33
- { name: 'parking', file: 'parking.config.json', defaults: PARKING_CFG_DEFAULTS, intKeys: PARKING_CFG_INT_KEYS },
34
- { name: 'promotion', file: 'promotion.config.json', defaults: PROMOTION_CFG_DEFAULTS, intKeys: PROMOTION_CFG_INT_KEYS },
35
- { name: 'shopping', file: 'shopping.config.json', defaults: SHOPPING_CFG_DEFAULTS, intKeys: SHOPPING_CFG_INT_KEYS },
36
- { name: 'mall-info', file: 'mall-info.config.json', defaults: MALL_INFO_CFG_DEFAULTS, intKeys: MALL_INFO_CFG_INT_KEYS },
37
- ];
38
-
39
- const readSchema = (file: string): SchemaFile =>
40
- JSON.parse(readFileSync(path.join(pkgRoot, 'schemas', file), 'utf8')) as SchemaFile;
41
-
42
- describe('provider-mock:config schema 双锁(供给面 ≡ 消费面)', () => {
43
- it('① 键集双向锁:schema.properties ≡ DEFAULTS 键集', () => {
44
- for (const d of DOMAINS) {
45
- const schema = readSchema(d.file);
46
- expect(Object.keys(schema.properties).sort(), `${d.name} 键集`).toEqual(Object.keys(d.defaults).sort());
47
- }
48
- });
49
-
50
- it('② default 漂移锁:schema 缺省 ≡ 实现缺省', () => {
51
- for (const d of DOMAINS) {
52
- const schema = readSchema(d.file);
53
- for (const [key, value] of Object.entries(d.defaults)) {
54
- expect(schema.properties[key]?.default, `${d.name}.${key} default 漂移`).toEqual(value);
55
- }
56
- }
57
- });
58
-
59
- it('③ 整数对偶锁:schema type=integer ⟺ INT_KEYS(分式字段不得入 intKeys)', () => {
60
- for (const d of DOMAINS) {
61
- const schema = readSchema(d.file);
62
- for (const [key, prop] of Object.entries(schema.properties)) {
63
- expect(prop.type === 'integer', `${d.name}.${key} 整数对偶`).toBe(d.intKeys.includes(key));
64
- }
65
- }
66
- });
67
-
68
- it('④ manifest 分发面锁:17 槽引用齐全 + 槽→域映射 + 文件随包', () => {
69
- const manifest = JSON.parse(readFileSync(path.join(pkgRoot, 'tbox.module.json'), 'utf8')) as {
70
- contributes: { providers: { slots: Array<{ service: string; configSchema?: string }> } };
71
- };
72
- const slots = manifest.contributes.providers.slots;
73
- expect(slots).toHaveLength(17);
74
- const fileOfPrefix: Record<string, string> = {
75
- member: 'member.config.json',
76
- parking: 'parking.config.json',
77
- promotion: 'promotion.config.json',
78
- 'shopping-guide': 'shopping.config.json',
79
- mall: 'mall-info.config.json',
80
- };
81
- for (const slot of slots) {
82
- const prefix = slot.service.slice(0, slot.service.indexOf('.'));
83
- expect(slot.configSchema, `${slot.service} configSchema 缺失`).toBe(`schemas/${fileOfPrefix[prefix]}`);
84
- expect(existsSync(path.join(pkgRoot, slot.configSchema!)), `${slot.service} schema 文件不存在`).toBe(true);
85
- }
86
- });
87
-
88
- it('⑤ 楼层 enum ≡ SHOPPING_FLOORS(消费点守卫与表单引导同源)', () => {
89
- const schema = readSchema('shopping.config.json');
90
- expect(schema.properties.extraShopFloor?.enum).toEqual([...SHOPPING_FLOORS]);
91
- });
92
- });