@lark-apaas/db-schema-sync 0.1.0-alpha.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/dist/bin.d.ts +1 -0
- package/dist/bin.js +442 -0
- package/dist/chunk-QO7QQCAM.js +2209 -0
- package/dist/index.d.ts +186 -0
- package/dist/index.js +15 -0
- package/package.json +42 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
interface SchemaData {
|
|
2
|
+
tables: TableSchema[];
|
|
3
|
+
views: ViewSchema[];
|
|
4
|
+
materializedViews: ViewSchema[];
|
|
5
|
+
enums: EnumSchema[];
|
|
6
|
+
sequences: SequenceSchema[];
|
|
7
|
+
syncedTableMap: SyncedTableMap;
|
|
8
|
+
}
|
|
9
|
+
interface TableSchema {
|
|
10
|
+
tableName: string;
|
|
11
|
+
identifier: string;
|
|
12
|
+
comment?: string;
|
|
13
|
+
fields: FieldSchema[];
|
|
14
|
+
relationships: RelationshipSchema[];
|
|
15
|
+
indexes: IndexSchema[];
|
|
16
|
+
}
|
|
17
|
+
interface FieldSchema {
|
|
18
|
+
fieldName: string;
|
|
19
|
+
type: string;
|
|
20
|
+
isPrimary: boolean;
|
|
21
|
+
isNullable: boolean;
|
|
22
|
+
isUnique: boolean;
|
|
23
|
+
isArray: boolean;
|
|
24
|
+
isEnum: boolean;
|
|
25
|
+
isSystem: boolean;
|
|
26
|
+
defaultValue?: string;
|
|
27
|
+
comment?: string;
|
|
28
|
+
extraInfo?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
interface RelationshipSchema {
|
|
31
|
+
fieldNames: string[];
|
|
32
|
+
targetTableName: string;
|
|
33
|
+
targetFieldNames: string[];
|
|
34
|
+
updatePolicy: string;
|
|
35
|
+
removePolicy: string;
|
|
36
|
+
}
|
|
37
|
+
interface IndexSchema {
|
|
38
|
+
indexName: string;
|
|
39
|
+
indexColumns: string[];
|
|
40
|
+
indexType: string;
|
|
41
|
+
indexCreationType?: string;
|
|
42
|
+
indexDef?: string;
|
|
43
|
+
}
|
|
44
|
+
interface ViewSchema {
|
|
45
|
+
viewName: string;
|
|
46
|
+
identifier: string;
|
|
47
|
+
comment?: string;
|
|
48
|
+
fields: FieldSchema[];
|
|
49
|
+
viewDef?: string;
|
|
50
|
+
}
|
|
51
|
+
interface EnumSchema {
|
|
52
|
+
enumName: string;
|
|
53
|
+
identifier: string;
|
|
54
|
+
values: string[];
|
|
55
|
+
}
|
|
56
|
+
interface SequenceSchema {
|
|
57
|
+
sequenceName: string;
|
|
58
|
+
identifier: string;
|
|
59
|
+
}
|
|
60
|
+
type SyncedTableMap = Map<string, Set<string>>;
|
|
61
|
+
interface ApiFieldItem {
|
|
62
|
+
fieldName: string;
|
|
63
|
+
type: string;
|
|
64
|
+
isPrimary: boolean;
|
|
65
|
+
isNullable: boolean;
|
|
66
|
+
isUnique: boolean;
|
|
67
|
+
isArray: boolean;
|
|
68
|
+
isEnum: boolean;
|
|
69
|
+
defaultValue?: string | null;
|
|
70
|
+
comment?: string;
|
|
71
|
+
extraInfo?: Record<string, unknown>;
|
|
72
|
+
arrayElementType?: string | null;
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
}
|
|
75
|
+
interface ApiRelationshipItem {
|
|
76
|
+
fieldName: string[];
|
|
77
|
+
fkTableName: string;
|
|
78
|
+
fkFieldName: string[];
|
|
79
|
+
fkSchema?: string;
|
|
80
|
+
updateMethod: string;
|
|
81
|
+
removeMethod: string;
|
|
82
|
+
[key: string]: unknown;
|
|
83
|
+
}
|
|
84
|
+
interface ApiIndexItem {
|
|
85
|
+
indexName: string;
|
|
86
|
+
indexColumns: string[] | null;
|
|
87
|
+
indexType: string;
|
|
88
|
+
indexCreationType?: string;
|
|
89
|
+
indexDef?: string;
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
interface ApiBitableSyncTask {
|
|
93
|
+
fieldApiNameList: string[];
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
}
|
|
96
|
+
interface ApiTableItem {
|
|
97
|
+
tableName: string;
|
|
98
|
+
comment?: string;
|
|
99
|
+
fields: ApiFieldItem[];
|
|
100
|
+
relationships?: ApiRelationshipItem[];
|
|
101
|
+
indexes?: ApiIndexItem[];
|
|
102
|
+
bitableSyncTask?: ApiBitableSyncTask;
|
|
103
|
+
tableDef?: string;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
interface ApiEnumValueItem {
|
|
107
|
+
enumValueName: string;
|
|
108
|
+
apiID?: string;
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
}
|
|
111
|
+
interface ApiEnumItem {
|
|
112
|
+
enumName: string;
|
|
113
|
+
enumValues?: ApiEnumValueItem[];
|
|
114
|
+
values?: string[];
|
|
115
|
+
[key: string]: unknown;
|
|
116
|
+
}
|
|
117
|
+
interface ApiSequenceItem {
|
|
118
|
+
sequenceName: string;
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* API response format. Supports both old and new interfaces:
|
|
123
|
+
* - Old (listTableView): { table, view, materializedView }
|
|
124
|
+
* - New (/v1/app/:appID/dataloom/schema): { tables, views, materializedViews, enums, sequences }
|
|
125
|
+
*/
|
|
126
|
+
interface ApiTableViewResponse {
|
|
127
|
+
table?: {
|
|
128
|
+
data: ApiTableItem[];
|
|
129
|
+
count: number;
|
|
130
|
+
};
|
|
131
|
+
view?: {
|
|
132
|
+
data: ApiTableItem[];
|
|
133
|
+
count: number;
|
|
134
|
+
};
|
|
135
|
+
materializedView?: {
|
|
136
|
+
data: ApiTableItem[];
|
|
137
|
+
count: number;
|
|
138
|
+
};
|
|
139
|
+
tables?: {
|
|
140
|
+
data: ApiTableItem[];
|
|
141
|
+
count: number;
|
|
142
|
+
};
|
|
143
|
+
views?: {
|
|
144
|
+
data: ApiTableItem[];
|
|
145
|
+
count: number;
|
|
146
|
+
};
|
|
147
|
+
materializedViews?: {
|
|
148
|
+
data: ApiTableItem[];
|
|
149
|
+
count: number;
|
|
150
|
+
};
|
|
151
|
+
enums?: ApiEnumItem[];
|
|
152
|
+
sequences?: ApiSequenceItem[];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface FetchOptions {
|
|
156
|
+
appId: string;
|
|
157
|
+
workspace: string;
|
|
158
|
+
dbBranch?: string;
|
|
159
|
+
timeoutMs?: number;
|
|
160
|
+
}
|
|
161
|
+
declare function resolveEnvOptions(env?: Record<string, string | undefined>): FetchOptions;
|
|
162
|
+
|
|
163
|
+
declare function normalizeApiResponse(response: ApiTableViewResponse): SchemaData;
|
|
164
|
+
|
|
165
|
+
declare function generateSchemaCode(data: SchemaData): string;
|
|
166
|
+
|
|
167
|
+
interface GenerateSchemaOptions extends FetchOptions {
|
|
168
|
+
/** Skip specific enhancers by name */
|
|
169
|
+
skipEnhancers?: string[];
|
|
170
|
+
/** Export custom type definitions (userProfile, fileAttachment, etc.). Default: false */
|
|
171
|
+
exportCustomTypes?: boolean;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Full pipeline: fetch API data → generate code → enhance.
|
|
175
|
+
* Returns the final schema.ts content as a string.
|
|
176
|
+
*/
|
|
177
|
+
declare function generateSchema(options: GenerateSchemaOptions): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Generate from pre-fetched SchemaData (useful for testing without API).
|
|
180
|
+
*/
|
|
181
|
+
declare function generateSchemaFromData(schemaData: SchemaData, options?: {
|
|
182
|
+
skipEnhancers?: string[];
|
|
183
|
+
exportCustomTypes?: boolean;
|
|
184
|
+
}): string;
|
|
185
|
+
|
|
186
|
+
export { type EnumSchema, type FetchOptions, type FieldSchema, type GenerateSchemaOptions, type SchemaData, type TableSchema, type ViewSchema, generateSchema, generateSchemaCode, generateSchemaFromData, normalizeApiResponse, resolveEnvOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
generateSchema,
|
|
4
|
+
generateSchemaCode,
|
|
5
|
+
generateSchemaFromData,
|
|
6
|
+
normalizeApiResponse,
|
|
7
|
+
resolveEnvOptions
|
|
8
|
+
} from "./chunk-QO7QQCAM.js";
|
|
9
|
+
export {
|
|
10
|
+
generateSchema,
|
|
11
|
+
generateSchemaCode,
|
|
12
|
+
generateSchemaFromData,
|
|
13
|
+
normalizeApiResponse,
|
|
14
|
+
resolveEnvOptions
|
|
15
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lark-apaas/db-schema-sync",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": "./dist/bin.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"dev": "tsup --watch",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@lark-apaas/http-client": "^0.1.2",
|
|
33
|
+
"dotenv": "^17.3.1",
|
|
34
|
+
"tiny-pinyin": "^1.3.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.0.0",
|
|
38
|
+
"tsup": "^8.3.5",
|
|
39
|
+
"typescript": "^5.9.2",
|
|
40
|
+
"vitest": "^3.2.4"
|
|
41
|
+
}
|
|
42
|
+
}
|