@lark-apaas/db-schema-sync 0.1.0-alpha.5 → 0.1.0-alpha.7
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/LICENSE +13 -0
- package/dist/bin.js +1 -1
- package/dist/{chunk-OF4XHR3O.js → chunk-OFEXLJ35.js} +99 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Lark Technologies Pte. Ltd. and/or its affiliates
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,provided that the above copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
8
|
+
IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
|
|
9
|
+
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
|
10
|
+
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
11
|
+
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
12
|
+
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
13
|
+
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/dist/bin.js
CHANGED
|
@@ -31,9 +31,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
mod
|
|
32
32
|
));
|
|
33
33
|
|
|
34
|
-
//
|
|
34
|
+
// ../../../node_modules/@lark-apaas/http-client/dist/index.js
|
|
35
35
|
var require_dist = __commonJS({
|
|
36
|
-
"
|
|
36
|
+
"../../../node_modules/@lark-apaas/http-client/dist/index.js"(exports, module) {
|
|
37
37
|
"use strict";
|
|
38
38
|
var __defProp2 = Object.defineProperty;
|
|
39
39
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -56,6 +56,7 @@ var require_dist = __commonJS({
|
|
|
56
56
|
__export(index_exports, {
|
|
57
57
|
DEFAULT_CLOCK_TOLERANCE_SEC: () => DEFAULT_CLOCK_TOLERANCE_SEC,
|
|
58
58
|
DEFAULT_JWT_EXPIRE_TIME_MS: () => DEFAULT_JWT_EXPIRE_TIME_MS,
|
|
59
|
+
FileTokenProvider: () => FileTokenProvider,
|
|
59
60
|
HttpClient: () => HttpClient2,
|
|
60
61
|
HttpError: () => HttpError,
|
|
61
62
|
generateJWTToken: () => generateJWTToken,
|
|
@@ -228,6 +229,77 @@ var require_dist = __commonJS({
|
|
|
228
229
|
};
|
|
229
230
|
}
|
|
230
231
|
};
|
|
232
|
+
var import_fs = __require("fs");
|
|
233
|
+
var DEFAULT_REFRESH_BEFORE_MS = 5 * 60 * 1e3;
|
|
234
|
+
var DEFAULT_TOKEN_PATHS = [
|
|
235
|
+
"/home/gem/workspace/.force/openclaw/miaoda-provider-key"
|
|
236
|
+
];
|
|
237
|
+
var FileTokenProvider = class {
|
|
238
|
+
cache = /* @__PURE__ */ new Map();
|
|
239
|
+
paths;
|
|
240
|
+
refreshBeforeMs;
|
|
241
|
+
constructor(config) {
|
|
242
|
+
this.paths = config?.paths ?? DEFAULT_TOKEN_PATHS;
|
|
243
|
+
this.refreshBeforeMs = config?.refreshBeforeMs ?? DEFAULT_REFRESH_BEFORE_MS;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 获取 token,按路径优先级依次尝试
|
|
247
|
+
*
|
|
248
|
+
* 1. 缓存有效且不在刷新窗口 → 直接返回
|
|
249
|
+
* 2. 进入刷新窗口 → 重读文件,更新缓存
|
|
250
|
+
* 3. 文件未更新但缓存未过期 → 仍返回旧缓存
|
|
251
|
+
* 4. 所有路径均无有效 token → 返回 null
|
|
252
|
+
*/
|
|
253
|
+
getToken() {
|
|
254
|
+
const now = Date.now();
|
|
255
|
+
for (const filePath of this.paths) {
|
|
256
|
+
const cached = this.cache.get(filePath);
|
|
257
|
+
if (cached && cached.expiresAtMs - now > this.refreshBeforeMs) {
|
|
258
|
+
return { token: cached.token, accessKey: cached.accessKey };
|
|
259
|
+
}
|
|
260
|
+
const result = this.readAndParse(filePath);
|
|
261
|
+
if (result) {
|
|
262
|
+
this.cache.set(filePath, result);
|
|
263
|
+
if (result.expiresAtMs > now) {
|
|
264
|
+
return { token: result.token, accessKey: result.accessKey };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (cached && cached.expiresAtMs > now) {
|
|
268
|
+
return { token: cached.token, accessKey: cached.accessKey };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
clearCache() {
|
|
274
|
+
this.cache.clear();
|
|
275
|
+
}
|
|
276
|
+
readAndParse(filePath) {
|
|
277
|
+
try {
|
|
278
|
+
const token = (0, import_fs.readFileSync)(filePath, "utf-8").trim();
|
|
279
|
+
if (!token) return null;
|
|
280
|
+
const payload = this.decodePayload(token);
|
|
281
|
+
if (!payload?.exp) return null;
|
|
282
|
+
return {
|
|
283
|
+
token,
|
|
284
|
+
accessKey: payload.access_key ?? "",
|
|
285
|
+
expiresAtMs: payload.exp * 1e3
|
|
286
|
+
};
|
|
287
|
+
} catch {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
decodePayload(token) {
|
|
292
|
+
try {
|
|
293
|
+
const segments = token.split(".");
|
|
294
|
+
if (segments.length !== 3) return null;
|
|
295
|
+
const padLength = (4 - (segments[1].length % 4 || 4)) % 4;
|
|
296
|
+
const padded = `${segments[1]}${"=".repeat(padLength)}`.replace(/-/g, "+").replace(/_/g, "/");
|
|
297
|
+
return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
|
|
298
|
+
} catch {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
231
303
|
var DEFAULT_DOMAIN_ENV = "FORCE_AUTHN_INNERAPI_DOMAIN";
|
|
232
304
|
var DEFAULT_ACCESS_KEY_ENV = "FORCE_AUTHN_ACCESS_KEY";
|
|
233
305
|
var DEFAULT_SECRET_KEY_ENV = "FORCE_AUTHN_ACCESS_SECRET";
|
|
@@ -250,6 +322,13 @@ var require_dist = __commonJS({
|
|
|
250
322
|
return void 0;
|
|
251
323
|
}
|
|
252
324
|
ensureNoAccessKeyOverride("platform.defaultClaims", options.defaultClaims);
|
|
325
|
+
let fileTokenProvider;
|
|
326
|
+
if (options.tokenProvider?.type === "file") {
|
|
327
|
+
fileTokenProvider = new FileTokenProvider({
|
|
328
|
+
paths: options.tokenProvider.paths,
|
|
329
|
+
refreshBeforeMs: options.refreshBeforeMs
|
|
330
|
+
});
|
|
331
|
+
}
|
|
253
332
|
const accessKeyEnv = options.accessKeyEnv || DEFAULT_ACCESS_KEY_ENV;
|
|
254
333
|
const secretKeyEnv = options.secretKeyEnv || DEFAULT_SECRET_KEY_ENV;
|
|
255
334
|
const accessKey = options.accessKey ?? (process.env[accessKeyEnv] || "");
|
|
@@ -262,6 +341,17 @@ var require_dist = __commonJS({
|
|
|
262
341
|
refreshBeforeMs: options.refreshBeforeMs
|
|
263
342
|
});
|
|
264
343
|
interceptors.request.use((config) => {
|
|
344
|
+
if (fileTokenProvider) {
|
|
345
|
+
const fileToken = fileTokenProvider.getToken();
|
|
346
|
+
if (fileToken) {
|
|
347
|
+
const headers2 = {
|
|
348
|
+
...config.headers,
|
|
349
|
+
"Authorization": `Bearer ${fileToken.token}`,
|
|
350
|
+
"x-api-key": fileToken.accessKey
|
|
351
|
+
};
|
|
352
|
+
return { ...config, headers: headers2 };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
265
355
|
ensureNoAccessKeyOverride("request.platformAuth.customClaims", config.platformAuth?.customClaims);
|
|
266
356
|
const claims = {
|
|
267
357
|
...options.defaultClaims || {},
|
|
@@ -973,7 +1063,10 @@ Body: ${body.slice(0, 500)}`);
|
|
|
973
1063
|
}
|
|
974
1064
|
const json = await response.json();
|
|
975
1065
|
const data = json.data;
|
|
976
|
-
|
|
1066
|
+
if (!data) {
|
|
1067
|
+
return {};
|
|
1068
|
+
}
|
|
1069
|
+
return data?.data ?? data?.schema ?? data ?? {};
|
|
977
1070
|
} catch (err) {
|
|
978
1071
|
if (err?.response) {
|
|
979
1072
|
const headers = err.response.headers;
|
|
@@ -1153,6 +1246,9 @@ function extractSyncedTableMap(tables) {
|
|
|
1153
1246
|
return map;
|
|
1154
1247
|
}
|
|
1155
1248
|
function normalizeApiResponse(response) {
|
|
1249
|
+
if (!response) {
|
|
1250
|
+
return { tables: [], views: [], materializedViews: [], enums: [], sequences: [], syncedTableMap: /* @__PURE__ */ new Map() };
|
|
1251
|
+
}
|
|
1156
1252
|
const usedTableIdentifiers = /* @__PURE__ */ new Set();
|
|
1157
1253
|
const usedViewIdentifiers = /* @__PURE__ */ new Set();
|
|
1158
1254
|
const usedMViewIdentifiers = /* @__PURE__ */ new Set();
|
package/dist/index.d.ts
CHANGED
|
@@ -162,7 +162,7 @@ interface FetchOptions {
|
|
|
162
162
|
}
|
|
163
163
|
declare function resolveEnvOptions(env?: Record<string, string | undefined>): FetchOptions;
|
|
164
164
|
|
|
165
|
-
declare function normalizeApiResponse(response: ApiTableViewResponse): SchemaData;
|
|
165
|
+
declare function normalizeApiResponse(response: ApiTableViewResponse | null | undefined): SchemaData;
|
|
166
166
|
|
|
167
167
|
declare function generateSchemaCode(data: SchemaData): string;
|
|
168
168
|
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/db-schema-sync",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"node": ">=18.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@lark-apaas/http-client": "
|
|
32
|
+
"@lark-apaas/http-client": "0.1.3-alpha.2",
|
|
33
33
|
"dotenv": "^17.3.1",
|
|
34
34
|
"tiny-pinyin": "^1.3.2"
|
|
35
35
|
},
|