dsh-lh-data 0.1.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.
Files changed (89) hide show
  1. package/README.md +332 -0
  2. package/cordis.patch.yml +7 -0
  3. package/lib/admin-contract.d.ts +274 -0
  4. package/lib/admin-http.d.ts +31 -0
  5. package/lib/admin-validate.d.ts +87 -0
  6. package/lib/admin.d.ts +60 -0
  7. package/lib/client.js +2969 -0
  8. package/lib/client.js.map +1 -0
  9. package/lib/datasource/columns.d.ts +13 -0
  10. package/lib/datasource/connection.d.ts +33 -0
  11. package/lib/datasource/connector/base.d.ts +21 -0
  12. package/lib/datasource/connector/mysql.d.ts +23 -0
  13. package/lib/datasource/connector/postgresql.d.ts +23 -0
  14. package/lib/datasource/crypto.d.ts +13 -0
  15. package/lib/datasource/driver.d.ts +39 -0
  16. package/lib/datasource/errors.d.ts +25 -0
  17. package/lib/datasource/importer.d.ts +38 -0
  18. package/lib/datasource/source-sql.d.ts +11 -0
  19. package/lib/datasource/source-store.d.ts +28 -0
  20. package/lib/datasource/types.d.ts +119 -0
  21. package/lib/db.d.ts +91 -0
  22. package/lib/http-common.d.ts +31 -0
  23. package/lib/http.d.ts +13 -0
  24. package/lib/index.d.ts +50 -0
  25. package/lib/index.js +5735 -0
  26. package/lib/parse.d.ts +41 -0
  27. package/lib/preview.d.ts +75 -0
  28. package/lib/render.d.ts +100 -0
  29. package/lib/scope-registry.d.ts +47 -0
  30. package/lib/scope.d.ts +56 -0
  31. package/lib/sql.d.ts +133 -0
  32. package/lib/store.d.ts +174 -0
  33. package/lib/table.d.ts +38 -0
  34. package/lib/tooling.d.ts +267 -0
  35. package/lib/tools/datasource.d.ts +16 -0
  36. package/lib/tools/import.d.ts +21 -0
  37. package/lib/tools/read.d.ts +77 -0
  38. package/lib/tools/registry.d.ts +12 -0
  39. package/lib/tools/write.d.ts +37 -0
  40. package/lib/view.d.ts +138 -0
  41. package/package.json +61 -0
  42. package/src/admin-contract.ts +351 -0
  43. package/src/admin-http.ts +254 -0
  44. package/src/admin-validate.ts +393 -0
  45. package/src/admin.ts +558 -0
  46. package/src/client/index.ts +403 -0
  47. package/src/client/settings/CreateForm.tsx +186 -0
  48. package/src/client/settings/DataSourceForm.tsx +278 -0
  49. package/src/client/settings/DataSourcesPanel.tsx +301 -0
  50. package/src/client/settings/DatasetEditor.tsx +245 -0
  51. package/src/client/settings/DatasetTable.tsx +110 -0
  52. package/src/client/settings/DatasetsPanel.tsx +207 -0
  53. package/src/client/settings/RowsPanel.tsx +196 -0
  54. package/src/client/settings/Section.tsx +41 -0
  55. package/src/client/settings/SourceTablesPanel.tsx +226 -0
  56. package/src/client/settings/api.ts +154 -0
  57. package/src/client/settings/styles.ts +125 -0
  58. package/src/datasource/columns.ts +56 -0
  59. package/src/datasource/connection.ts +124 -0
  60. package/src/datasource/connector/base.ts +54 -0
  61. package/src/datasource/connector/mysql.ts +187 -0
  62. package/src/datasource/connector/postgresql.ts +212 -0
  63. package/src/datasource/crypto.ts +61 -0
  64. package/src/datasource/driver.ts +108 -0
  65. package/src/datasource/errors.ts +69 -0
  66. package/src/datasource/importer.ts +262 -0
  67. package/src/datasource/index.ts +62 -0
  68. package/src/datasource/source-sql.ts +64 -0
  69. package/src/datasource/source-store.ts +152 -0
  70. package/src/datasource/types.ts +133 -0
  71. package/src/db.ts +277 -0
  72. package/src/http-common.ts +91 -0
  73. package/src/http.ts +130 -0
  74. package/src/index.ts +486 -0
  75. package/src/parse.ts +213 -0
  76. package/src/preview.ts +198 -0
  77. package/src/render.ts +294 -0
  78. package/src/scope-registry.ts +111 -0
  79. package/src/scope.ts +159 -0
  80. package/src/sql.ts +491 -0
  81. package/src/store.ts +412 -0
  82. package/src/table.ts +160 -0
  83. package/src/tooling.ts +551 -0
  84. package/src/tools/datasource.ts +378 -0
  85. package/src/tools/import.ts +282 -0
  86. package/src/tools/read.ts +536 -0
  87. package/src/tools/registry.ts +56 -0
  88. package/src/tools/write.ts +241 -0
  89. package/src/view.ts +371 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * 设置页管理接口的入参校验(纯函数,无 IO)。
3
+ *
4
+ * 所有校验失败都抛 `AdminValidationError`,由 `admin-http.ts` 统一转成 400。
5
+ * 校验目标:把浏览器传来的任意字符串收口成「类型正确、长度受控、范围合法」
6
+ * 的值——写库前最后一道闸门,尤其要防止凭空造工作区、列结构越界、字段溢出。
7
+ */
8
+ import { type ColumnInfo } from './parse';
9
+ import type { DataSourceInput, DataSourcePatch, DataSourceType } from './datasource/types';
10
+ import type { ConnectionDraft } from './datasource/connection';
11
+ import { type AdminErrorCode } from './admin-contract';
12
+ /** 校验失败:对应 HTTP 400。 */
13
+ export declare class AdminValidationError extends Error {
14
+ readonly code: AdminErrorCode;
15
+ constructor(code: AdminErrorCode, message: string);
16
+ }
17
+ export declare function validateScopeKey(value: unknown): string;
18
+ export declare function validateDatasetName(value: unknown): string;
19
+ export declare function validateDescription(value: unknown): string | null;
20
+ export declare function validateSourcePath(value: unknown): string | null;
21
+ /**
22
+ * 校验列定义:非空数组、数量受控、类型白名单、列名消毒并去重。
23
+ * 返回可直接交给 `createDatasetTable` 的 `ColumnInfo[]`。
24
+ */
25
+ export declare function validateColumnSpecs(raw: unknown): ColumnInfo[];
26
+ /**
27
+ * 校验列的「说明 / 样例」补丁,返回合并后的完整 `ColumnInfo[]`。
28
+ *
29
+ * 只从补丁里读 `description` 与 `sample` 两项,其余字段(name / sanitizedName /
30
+ * type / nullable)一律沿用既有列——它们对应物理表 DDL,设置页改不了。
31
+ * 按 `sanitizedName` 定位列:原始表头 `name` 在重名列上会重复,不能当键。
32
+ */
33
+ export declare function validateColumnPatches(raw: unknown, existing: ColumnInfo[]): ColumnInfo[];
34
+ export interface ParsedListQuery {
35
+ q: string;
36
+ page: number;
37
+ pageSize: number;
38
+ }
39
+ /** 解析并夹紧列表查询参数(关键字裁剪、页码与页大小封顶)。 */
40
+ export declare function parseListQuery(params: Record<string, string | undefined>): ParsedListQuery;
41
+ export interface ParsedRowsQuery {
42
+ page: number;
43
+ pageSize: number;
44
+ }
45
+ /**
46
+ * 解析并夹紧表数据分页参数。页码上限只是防御(真实边界由 `COUNT(*)` 决定),
47
+ * 页大小封顶避免一次捞走整表。
48
+ */
49
+ export declare function parseRowsQuery(params: Record<string, string | undefined>): ParsedRowsQuery;
50
+ export declare function validateSourceName(value: unknown): string;
51
+ export declare function validateSourceType(value: unknown): DataSourceType;
52
+ export declare function validateHost(value: unknown): string;
53
+ export declare function validatePort(value: unknown, type: DataSourceType): number;
54
+ export declare function validateDatabaseName(value: unknown): string;
55
+ export declare function validateUsername(value: unknown): string;
56
+ /** 密码允许为空串(部分库无口令),但不能超过上限。 */
57
+ export declare function validatePassword(value: unknown): string;
58
+ export interface ParsedCreateSource extends DataSourceInput {
59
+ test: boolean;
60
+ }
61
+ export declare function parseCreateDataSource(raw: unknown): ParsedCreateSource;
62
+ export interface ParsedPatchSource extends DataSourcePatch {
63
+ test: boolean;
64
+ }
65
+ /** 只校验出现的字段;`password` 给了字符串才替换。 */
66
+ export declare function parsePatchDataSource(raw: unknown): ParsedPatchSource;
67
+ export interface ParsedTestSource {
68
+ /** 测已登记的数据源(id 或登记名)。 */
69
+ reference?: string;
70
+ /** 测未保存的草稿。 */
71
+ draft?: ConnectionDraft;
72
+ }
73
+ /** `source` 与「完整连接参数」二选一。 */
74
+ export declare function parseTestDataSource(raw: unknown): ParsedTestSource;
75
+ export interface ParsedTablesQuery {
76
+ schema: string | null;
77
+ q: string;
78
+ }
79
+ export declare function parseTablesQuery(params: Record<string, string | undefined>): ParsedTablesQuery;
80
+ export interface ParsedImportRequest {
81
+ scopeKey: string;
82
+ tableName: string;
83
+ schemaName: string | null;
84
+ name: string | null;
85
+ limit: number | null;
86
+ }
87
+ export declare function parseImportRequest(raw: unknown): ParsedImportRequest;
package/lib/admin.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 设置页管理接口的主机侧服务层(模块级函数,无类)。
3
+ *
4
+ * 负责跨工作区聚合、单条详情、新建/改名改描述改来源/删除等纯业务逻辑,
5
+ * 不含任何 HTTP 细节(路由在 `admin-http.ts`)。所有错误都收敛成
6
+ * `AdminServiceError`,由路由层映射到统一脱敏的 JSON 错误体。
7
+ *
8
+ * 关键约束:
9
+ * - 写操作先过 `assertWritable`(readOnly / adminEnabled 门禁);
10
+ * - 写与读都先校验 scope 是否「已知」(来自工作区注册表),拒绝凭空造工作区;
11
+ * - 物理表名一律由 `generateTableName` 生成并经 `assertPhysicalTableName` 白名单,
12
+ * 错误信息不回显表名与 SQL。
13
+ */
14
+ import type { DataServices } from './store';
15
+ import { type AdminErrorCode, type ConnectionTestView, type CreateDatasetRequest, type DataSourceView, type DatasetDetailView, type DatasetRowsResult, type ImportSourceTableResult, type ListDatasetsResult, type ListSourceTablesResult, type PatchDatasetRequest, type ScopeView } from './admin-contract';
16
+ /** 业务错误:携带 HTTP 状态码与脱敏后的错误信息。 */
17
+ export declare class AdminServiceError extends Error {
18
+ readonly code: AdminErrorCode;
19
+ readonly status: number;
20
+ constructor(code: AdminErrorCode, status: number, message: string);
21
+ }
22
+ /** 只读模式或接口关闭时拒绝写操作。 */
23
+ export declare function assertWritable(services: DataServices): void;
24
+ export declare function listScopes(services: DataServices): Promise<ScopeView[]>;
25
+ /**
26
+ * 聚合所有工作区的数据集:逐 scope 拉取后内存过滤、排序、分页。
27
+ * 单个工作区读取失败降级为一条 warning 而不阻断整页。
28
+ */
29
+ export declare function listDatasets(services: DataServices, rawQuery: Record<string, string | undefined>): Promise<ListDatasetsResult>;
30
+ export declare function getDataset(services: DataServices, scopeKey: string, id: string): Promise<DatasetDetailView>;
31
+ /**
32
+ * 只读分页读取某个数据集的物理表行。
33
+ *
34
+ * 只按 `_row_id` 升序翻页(稳定、不重不漏),列名取自元数据登记的业务列,
35
+ * 系统列(`_row_id` / `_uploaded_at`)不进 `columns`,但 `_row_id` 会出现在
36
+ * 每行里,供前端做稳定行键。页码由 `COUNT(*)` 反推后夹紧,越界返回末页。
37
+ */
38
+ export declare function listDatasetRows(services: DataServices, scopeKey: string, id: string, rawQuery: Record<string, string | undefined>): Promise<DatasetRowsResult>;
39
+ /** 新建一张空物理表并登记元数据;列结构在提交时冻结。 */
40
+ export declare function createDataset(services: DataServices, raw: CreateDatasetRequest): Promise<DatasetDetailView>;
41
+ /** 改名 / 改描述 / 改来源 / 改列的说明与样例;未提供的字段保持不变;同工作区内名称唯一。 */
42
+ export declare function patchDataset(services: DataServices, scopeKey: string, id: string, raw: PatchDatasetRequest): Promise<DatasetDetailView>;
43
+ export interface DeleteDatasetResult {
44
+ id: string;
45
+ name: string;
46
+ dropped: boolean;
47
+ }
48
+ /** 连同物理表与元数据一起删除(等同 dataset_drop)。 */
49
+ export declare function deleteDataset(services: DataServices, scopeKey: string, id: string): Promise<DeleteDatasetResult>;
50
+ export declare function listDataSources(services: DataServices): Promise<DataSourceView[]>;
51
+ export declare function getDataSource(services: DataServices, reference: string): Promise<DataSourceView>;
52
+ export declare function createDataSource(services: DataServices, raw: unknown): Promise<DataSourceView>;
53
+ export declare function patchDataSource(services: DataServices, reference: string, raw: unknown): Promise<DataSourceView>;
54
+ export declare function deleteDataSource(services: DataServices, reference: string): Promise<{
55
+ deleted: boolean;
56
+ }>;
57
+ /** 测已登记的数据源(`source`)或未保存的草稿(完整连接参数)。 */
58
+ export declare function testDataSource(services: DataServices, raw: unknown): Promise<ConnectionTestView>;
59
+ export declare function listSourceTables(services: DataServices, reference: string, params: Record<string, string | undefined>): Promise<ListSourceTablesResult>;
60
+ export declare function importSourceTable(services: DataServices, reference: string, raw: unknown): Promise<ImportSourceTableResult>;