@lark-apaas/db-schema-sync 0.1.15 → 0.1.16-alpha.20260827043727

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.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  __toESM,
7
7
  generateSchema,
8
8
  resolveEnvOptions
9
- } from "./chunk-AUBN2ZMK.js";
9
+ } from "./chunk-2AZD4BS3.js";
10
10
 
11
11
  // node_modules/dotenv/package.json
12
12
  var require_package = __commonJS({
@@ -1269,7 +1269,36 @@ function getUniqueIdentifier(name, usedIdentifiers, kind = "table") {
1269
1269
  }
1270
1270
 
1271
1271
  // src/fetcher/normalize.ts
1272
- var SYSTEM_FIELD_NAMES = /* @__PURE__ */ new Set(["_created_at", "_created_by", "_updated_at", "_updated_by"]);
1272
+ var SYSTEM_FIELD_NAMES = /* @__PURE__ */ new Set([
1273
+ "_created_at",
1274
+ "_created_by",
1275
+ "_updated_at",
1276
+ "_updated_by"
1277
+ ]);
1278
+ function hasIdentityGenerationValue(field) {
1279
+ return Object.prototype.hasOwnProperty.call(field, "identityGeneration");
1280
+ }
1281
+ function resolveIdentityGeneration(field) {
1282
+ if (field.identityGeneration === "always" || field.identityGeneration === "byDefault") {
1283
+ return field.identityGeneration;
1284
+ }
1285
+ if (!hasIdentityGenerationValue(field) || field.identityGeneration === null || field.identityGeneration === void 0) {
1286
+ if (field.isIdentity === true) {
1287
+ console.warn(
1288
+ `[db-schema-sync] field "${field.fieldName}" still uses legacy isIdentity=true; falling back to identityGeneration=always`
1289
+ );
1290
+ return "always";
1291
+ }
1292
+ }
1293
+ if (hasIdentityGenerationValue(field) && field.identityGeneration != null && field.isIdentity === true) {
1294
+ console.warn(
1295
+ `[db-schema-sync] field "${field.fieldName}" has unsupported identityGeneration="${String(
1296
+ field.identityGeneration
1297
+ )}"; ignoring legacy isIdentity fallback`
1298
+ );
1299
+ }
1300
+ return void 0;
1301
+ }
1273
1302
  function normalizeField(field, systemFieldNamesToRemove) {
1274
1303
  if (systemFieldNamesToRemove.has(field.fieldName)) {
1275
1304
  return null;
@@ -1283,6 +1312,8 @@ function normalizeField(field, systemFieldNamesToRemove) {
1283
1312
  isArray: field.isArray,
1284
1313
  isEnum: field.isEnum,
1285
1314
  isSystem: SYSTEM_FIELD_NAMES.has(field.fieldName),
1315
+ isIdentity: field.isIdentity,
1316
+ identityGeneration: resolveIdentityGeneration(field),
1286
1317
  defaultValue: field.defaultValue ?? void 0,
1287
1318
  comment: field.comment || void 0,
1288
1319
  extraInfo: field.extraInfo
@@ -1326,7 +1357,11 @@ function resolveSystemFieldConflicts(fields) {
1326
1357
  return toRemove;
1327
1358
  }
1328
1359
  function normalizeTable(table, usedIdentifiers) {
1329
- const identifier = getUniqueIdentifier(table.tableName, usedIdentifiers, "table");
1360
+ const identifier = getUniqueIdentifier(
1361
+ table.tableName,
1362
+ usedIdentifiers,
1363
+ "table"
1364
+ );
1330
1365
  const systemFieldsToRemove = resolveSystemFieldConflicts(table.fields ?? []);
1331
1366
  const fields = [];
1332
1367
  for (const field of table.fields ?? []) {
@@ -1335,7 +1370,9 @@ function normalizeTable(table, usedIdentifiers) {
1335
1370
  fields.push(normalized);
1336
1371
  }
1337
1372
  }
1338
- const relationships = (table.relationships ?? []).map(normalizeRelationship);
1373
+ const relationships = (table.relationships ?? []).map(
1374
+ normalizeRelationship
1375
+ );
1339
1376
  const indexes = (table.indexes ?? []).map(normalizeIndex);
1340
1377
  return {
1341
1378
  tableName: table.tableName,
@@ -1375,14 +1412,25 @@ function extractSyncedTableMap(tables) {
1375
1412
  }
1376
1413
  function normalizeApiResponse(response) {
1377
1414
  if (!response) {
1378
- return { tables: [], views: [], materializedViews: [], enums: [], sequences: [], syncedTableMap: /* @__PURE__ */ new Map() };
1415
+ return {
1416
+ tables: [],
1417
+ views: [],
1418
+ materializedViews: [],
1419
+ enums: [],
1420
+ sequences: [],
1421
+ syncedTableMap: /* @__PURE__ */ new Map()
1422
+ };
1379
1423
  }
1380
1424
  const usedIdentifiers = /* @__PURE__ */ new Set();
1381
1425
  const tableItems = response.tables?.data ?? response.table?.data ?? [];
1382
1426
  const viewItems = response.views?.data ?? response.view?.data ?? [];
1383
1427
  const mViewItems = response.materializedViews?.data ?? response.materializedView?.data ?? [];
1384
- const tables = tableItems.map((t) => normalizeTable(t, usedIdentifiers));
1385
- const views = viewItems.map((v) => normalizeView(v, usedIdentifiers, "view"));
1428
+ const tables = tableItems.map(
1429
+ (t) => normalizeTable(t, usedIdentifiers)
1430
+ );
1431
+ const views = viewItems.map(
1432
+ (v) => normalizeView(v, usedIdentifiers, "view")
1433
+ );
1386
1434
  const materializedViews = mViewItems.map(
1387
1435
  (v) => normalizeView(v, usedIdentifiers, "materializedView")
1388
1436
  );
@@ -1403,7 +1451,11 @@ function normalizeApiResponse(response) {
1403
1451
  });
1404
1452
  const sequences = (response.sequences ?? []).map((s) => ({
1405
1453
  sequenceName: s.sequenceName,
1406
- identifier: getUniqueIdentifier(s.sequenceName, usedIdentifiers, "sequence")
1454
+ identifier: getUniqueIdentifier(
1455
+ s.sequenceName,
1456
+ usedIdentifiers,
1457
+ "sequence"
1458
+ )
1407
1459
  }));
1408
1460
  const allRawTables = [...tableItems, ...viewItems, ...mViewItems];
1409
1461
  const syncedTableMap = extractSyncedTableMap(allRawTables);
@@ -1749,12 +1801,20 @@ function formatDefaultValue(value, field) {
1749
1801
  }
1750
1802
 
1751
1803
  // src/generator/field-modifier.ts
1804
+ function supportsIdentity(field) {
1805
+ return !field.isArray && ["int4", "integer", "int8", "bigint"].includes(field.type);
1806
+ }
1752
1807
  var defaultModifiers = [
1753
1808
  {
1754
1809
  name: "primaryKey",
1755
1810
  match: (f) => f.isPrimary,
1756
1811
  modify: () => ".primaryKey()"
1757
1812
  },
1813
+ {
1814
+ name: "identityGeneration",
1815
+ match: (f) => supportsIdentity(f) && (f.identityGeneration === "always" || f.identityGeneration === "byDefault"),
1816
+ modify: (f) => f.identityGeneration === "always" ? ".generatedAlwaysAsIdentity()" : ".generatedByDefaultAsIdentity()"
1817
+ },
1758
1818
  {
1759
1819
  name: "notNull",
1760
1820
  match: (f) => !f.isNullable && !f.isPrimary,
package/dist/index.d.ts CHANGED
@@ -23,6 +23,8 @@ interface FieldSchema {
23
23
  isArray: boolean;
24
24
  isEnum: boolean;
25
25
  isSystem: boolean;
26
+ isIdentity?: boolean;
27
+ identityGeneration?: 'always' | 'byDefault';
26
28
  defaultValue?: string;
27
29
  comment?: string;
28
30
  extraInfo?: Record<string, unknown>;
@@ -67,6 +69,8 @@ interface ApiFieldItem {
67
69
  isUnique: boolean;
68
70
  isArray: boolean;
69
71
  isEnum: boolean;
72
+ isIdentity?: boolean;
73
+ identityGeneration?: 'always' | 'byDefault';
70
74
  defaultValue?: string | null;
71
75
  comment?: string;
72
76
  extraInfo?: Record<string, unknown>;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  generateSchemaFromData,
6
6
  normalizeApiResponse,
7
7
  resolveEnvOptions
8
- } from "./chunk-AUBN2ZMK.js";
8
+ } from "./chunk-2AZD4BS3.js";
9
9
  export {
10
10
  generateSchema,
11
11
  generateSchemaCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/db-schema-sync",
3
- "version": "0.1.15",
3
+ "version": "0.1.16-alpha.20260827043727",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",