appwrite-cli 9.0.2 → 9.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 (32) hide show
  1. package/README.md +2 -2
  2. package/docs/examples/databases/create-line-attribute.md +5 -0
  3. package/docs/examples/databases/create-point-attribute.md +5 -0
  4. package/docs/examples/databases/create-polygon-attribute.md +5 -0
  5. package/docs/examples/databases/update-line-attribute.md +5 -0
  6. package/docs/examples/databases/update-point-attribute.md +5 -0
  7. package/docs/examples/databases/update-polygon-attribute.md +5 -0
  8. package/docs/examples/tablesdb/create-line-column.md +5 -0
  9. package/docs/examples/tablesdb/create-point-column.md +5 -0
  10. package/docs/examples/tablesdb/create-polygon-column.md +5 -0
  11. package/docs/examples/tablesdb/update-line-column.md +5 -0
  12. package/docs/examples/tablesdb/update-point-column.md +5 -0
  13. package/docs/examples/tablesdb/update-polygon-column.md +5 -0
  14. package/install.ps1 +2 -2
  15. package/install.sh +1 -1
  16. package/lib/client.js +2 -2
  17. package/lib/commands/databases.js +330 -0
  18. package/lib/commands/functions.js +2 -2
  19. package/lib/commands/generic.js +5 -5
  20. package/lib/commands/init.js +3 -1
  21. package/lib/commands/pull.js +8 -2
  22. package/lib/commands/push.js +27 -9
  23. package/lib/commands/tables-db.js +330 -0
  24. package/lib/commands/types.js +54 -15
  25. package/lib/config.js +57 -33
  26. package/lib/parser.js +1 -1
  27. package/lib/questions.js +6 -6
  28. package/lib/type-generation/languages/csharp.js +170 -0
  29. package/lib/type-generation/languages/javascript.js +2 -2
  30. package/lib/type-generation/languages/typescript.js +1 -1
  31. package/package.json +1 -1
  32. package/scoop/appwrite.config.json +3 -3
@@ -51,7 +51,9 @@ const {
51
51
  } = require("./databases");
52
52
  const {
53
53
  tablesDBGet,
54
- tablesDBGetTable
54
+ tablesDBGetTable,
55
+ tablesDBUpdateTable,
56
+ tablesDBCreateTable
55
57
  } = require("./tables-db");
56
58
  const {
57
59
  storageGetBucket, storageUpdateBucket, storageCreateBucket
@@ -892,7 +894,7 @@ const createIndexes = async (indexes, collection) => {
892
894
  );
893
895
 
894
896
  if (!result) {
895
- throw new Error("Index creation timed out.");
897
+ throw new Error('Index creation timed out.');
896
898
  }
897
899
 
898
900
  success(`Created ${indexes.length} indexes`);
@@ -916,6 +918,25 @@ const createAttributes = async (attributes, collection) => {
916
918
 
917
919
  success(`Created ${attributes.length} attributes`);
918
920
  }
921
+ const createColumns = async (columns, table) => {
922
+ for (let column of columns) {
923
+ if (column.side !== 'child') {
924
+ await createAttribute(table['databaseId'], table['$id'], column);
925
+ }
926
+ }
927
+
928
+ const result = await awaitPools.expectAttributes(
929
+ table['databaseId'],
930
+ table['$id'],
931
+ table.columns.filter(column => column.side !== 'child').map(column => column.key)
932
+ );
933
+
934
+ if (!result) {
935
+ throw new Error(`Column creation timed out.`);
936
+ }
937
+
938
+ success(`Created ${columns.length} columns`);
939
+ }
919
940
 
920
941
  const pushResources = async () => {
921
942
  const actions = {
@@ -1711,7 +1732,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1711
1732
 
1712
1733
  // Parallel db actions
1713
1734
  await Promise.all(databases.map(async (databaseId) => {
1714
- const localDatabase = localConfig.getDatabase(databaseId);
1735
+ const localDatabase = localConfig.getTablesDB(databaseId);
1715
1736
 
1716
1737
  try {
1717
1738
  const database = await tablesDBGet({
@@ -1753,11 +1774,10 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1753
1774
  });
1754
1775
 
1755
1776
  if (remoteTable.name !== table.name) {
1756
- await databasesUpdateTable({
1777
+ await tablesDBUpdateTable({
1757
1778
  databaseId: table['databaseId'],
1758
1779
  tableId: table['$id'],
1759
1780
  name: table.name,
1760
- name: table.name,
1761
1781
  parseOutput: false
1762
1782
  })
1763
1783
 
@@ -1770,7 +1790,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1770
1790
  (e) {
1771
1791
  if (Number(e.code) === 404) {
1772
1792
  log(`Table ${table.name} does not exist in the project. Creating ... `);
1773
- await databasesCreateTable({
1793
+ await tablesDBCreateTable({
1774
1794
  databaseId: table['databaseId'],
1775
1795
  tableId: table['$id'],
1776
1796
  name: table.name,
@@ -1796,13 +1816,12 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1796
1816
  if ((Array.isArray(columns) && columns.length <= 0) && (Array.isArray(indexes) && indexes.length <= 0)) {
1797
1817
  continue;
1798
1818
  }
1799
-
1800
1819
  }
1801
1820
 
1802
1821
  log(`Pushing table ${table.name} ( ${table['databaseId']} - ${table['$id']} ) attributes`)
1803
1822
 
1804
1823
  try {
1805
- await createAttributes(columns, table)
1824
+ await createColumns(columns, table)
1806
1825
  } catch (e) {
1807
1826
  throw e;
1808
1827
  }
@@ -1900,7 +1919,6 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
1900
1919
  databaseId: collection['databaseId'],
1901
1920
  collectionId: collection['$id'],
1902
1921
  name: collection.name,
1903
- name: collection.name,
1904
1922
  parseOutput: false
1905
1923
  })
1906
1924
 
@@ -1178,6 +1178,267 @@ const tablesDBUpdateIpColumn = async ({databaseId,tableId,key,required,xdefault,
1178
1178
 
1179
1179
  return response;
1180
1180
 
1181
+ }
1182
+ /**
1183
+ * @typedef {Object} TablesDBCreateLineColumnRequestParams
1184
+ * @property {string} databaseId Database ID.
1185
+ * @property {string} tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
1186
+ * @property {string} key Column Key.
1187
+ * @property {boolean} required Is column required?
1188
+ * @property {string} xdefault Default value for column when not provided, as JSON string. Cannot be set when column is required.
1189
+ * @property {boolean} overrideForCli
1190
+ * @property {boolean} parseOutput
1191
+ * @property {libClient | undefined} sdk
1192
+ */
1193
+
1194
+ /**
1195
+ * @param {TablesDBCreateLineColumnRequestParams} params
1196
+ */
1197
+ const tablesDBCreateLineColumn = async ({databaseId,tableId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
1198
+ let client = !sdk ? await sdkForProject() :
1199
+ sdk;
1200
+ let apiPath = '/tablesdb/{databaseId}/tables/{tableId}/columns/line'.replace('{databaseId}', databaseId).replace('{tableId}', tableId);
1201
+ let payload = {};
1202
+ if (typeof key !== 'undefined') {
1203
+ payload['key'] = key;
1204
+ }
1205
+ if (typeof required !== 'undefined') {
1206
+ payload['required'] = required;
1207
+ }
1208
+ if (typeof xdefault !== 'undefined') {
1209
+ payload['default'] = xdefault;
1210
+ }
1211
+
1212
+ let response = undefined;
1213
+
1214
+ response = await client.call('post', apiPath, {
1215
+ 'content-type': 'application/json',
1216
+ }, payload);
1217
+
1218
+ if (parseOutput) {
1219
+ parse(response)
1220
+ }
1221
+
1222
+ return response;
1223
+
1224
+ }
1225
+ /**
1226
+ * @typedef {Object} TablesDBUpdateLineColumnRequestParams
1227
+ * @property {string} databaseId Database ID.
1228
+ * @property {string} tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
1229
+ * @property {string} key Column Key.
1230
+ * @property {boolean} required Is column required?
1231
+ * @property {string} xdefault Default value for column when not provided, as JSON string. Cannot be set when column is required.
1232
+ * @property {string} newKey New Column Key.
1233
+ * @property {boolean} overrideForCli
1234
+ * @property {boolean} parseOutput
1235
+ * @property {libClient | undefined} sdk
1236
+ */
1237
+
1238
+ /**
1239
+ * @param {TablesDBUpdateLineColumnRequestParams} params
1240
+ */
1241
+ const tablesDBUpdateLineColumn = async ({databaseId,tableId,key,required,xdefault,newKey,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
1242
+ let client = !sdk ? await sdkForProject() :
1243
+ sdk;
1244
+ let apiPath = '/tablesdb/{databaseId}/tables/{tableId}/columns/line/{key}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{key}', key);
1245
+ let payload = {};
1246
+ if (typeof required !== 'undefined') {
1247
+ payload['required'] = required;
1248
+ }
1249
+ if (typeof xdefault !== 'undefined') {
1250
+ payload['default'] = xdefault;
1251
+ }
1252
+ if (typeof newKey !== 'undefined') {
1253
+ payload['newKey'] = newKey;
1254
+ }
1255
+
1256
+ let response = undefined;
1257
+
1258
+ response = await client.call('patch', apiPath, {
1259
+ 'content-type': 'application/json',
1260
+ }, payload);
1261
+
1262
+ if (parseOutput) {
1263
+ parse(response)
1264
+ }
1265
+
1266
+ return response;
1267
+
1268
+ }
1269
+ /**
1270
+ * @typedef {Object} TablesDBCreatePointColumnRequestParams
1271
+ * @property {string} databaseId Database ID.
1272
+ * @property {string} tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
1273
+ * @property {string} key Column Key.
1274
+ * @property {boolean} required Is column required?
1275
+ * @property {string} xdefault Default value for column when not provided, as JSON string. Cannot be set when column is required.
1276
+ * @property {boolean} overrideForCli
1277
+ * @property {boolean} parseOutput
1278
+ * @property {libClient | undefined} sdk
1279
+ */
1280
+
1281
+ /**
1282
+ * @param {TablesDBCreatePointColumnRequestParams} params
1283
+ */
1284
+ const tablesDBCreatePointColumn = async ({databaseId,tableId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
1285
+ let client = !sdk ? await sdkForProject() :
1286
+ sdk;
1287
+ let apiPath = '/tablesdb/{databaseId}/tables/{tableId}/columns/point'.replace('{databaseId}', databaseId).replace('{tableId}', tableId);
1288
+ let payload = {};
1289
+ if (typeof key !== 'undefined') {
1290
+ payload['key'] = key;
1291
+ }
1292
+ if (typeof required !== 'undefined') {
1293
+ payload['required'] = required;
1294
+ }
1295
+ if (typeof xdefault !== 'undefined') {
1296
+ payload['default'] = xdefault;
1297
+ }
1298
+
1299
+ let response = undefined;
1300
+
1301
+ response = await client.call('post', apiPath, {
1302
+ 'content-type': 'application/json',
1303
+ }, payload);
1304
+
1305
+ if (parseOutput) {
1306
+ parse(response)
1307
+ }
1308
+
1309
+ return response;
1310
+
1311
+ }
1312
+ /**
1313
+ * @typedef {Object} TablesDBUpdatePointColumnRequestParams
1314
+ * @property {string} databaseId Database ID.
1315
+ * @property {string} tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
1316
+ * @property {string} key Column Key.
1317
+ * @property {boolean} required Is column required?
1318
+ * @property {string} xdefault Default value for column when not provided, as JSON string. Cannot be set when column is required.
1319
+ * @property {string} newKey New Column Key.
1320
+ * @property {boolean} overrideForCli
1321
+ * @property {boolean} parseOutput
1322
+ * @property {libClient | undefined} sdk
1323
+ */
1324
+
1325
+ /**
1326
+ * @param {TablesDBUpdatePointColumnRequestParams} params
1327
+ */
1328
+ const tablesDBUpdatePointColumn = async ({databaseId,tableId,key,required,xdefault,newKey,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
1329
+ let client = !sdk ? await sdkForProject() :
1330
+ sdk;
1331
+ let apiPath = '/tablesdb/{databaseId}/tables/{tableId}/columns/point/{key}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{key}', key);
1332
+ let payload = {};
1333
+ if (typeof required !== 'undefined') {
1334
+ payload['required'] = required;
1335
+ }
1336
+ if (typeof xdefault !== 'undefined') {
1337
+ payload['default'] = xdefault;
1338
+ }
1339
+ if (typeof newKey !== 'undefined') {
1340
+ payload['newKey'] = newKey;
1341
+ }
1342
+
1343
+ let response = undefined;
1344
+
1345
+ response = await client.call('patch', apiPath, {
1346
+ 'content-type': 'application/json',
1347
+ }, payload);
1348
+
1349
+ if (parseOutput) {
1350
+ parse(response)
1351
+ }
1352
+
1353
+ return response;
1354
+
1355
+ }
1356
+ /**
1357
+ * @typedef {Object} TablesDBCreatePolygonColumnRequestParams
1358
+ * @property {string} databaseId Database ID.
1359
+ * @property {string} tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
1360
+ * @property {string} key Column Key.
1361
+ * @property {boolean} required Is column required?
1362
+ * @property {string} xdefault Default value for column when not provided, as JSON string. Cannot be set when column is required.
1363
+ * @property {boolean} overrideForCli
1364
+ * @property {boolean} parseOutput
1365
+ * @property {libClient | undefined} sdk
1366
+ */
1367
+
1368
+ /**
1369
+ * @param {TablesDBCreatePolygonColumnRequestParams} params
1370
+ */
1371
+ const tablesDBCreatePolygonColumn = async ({databaseId,tableId,key,required,xdefault,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
1372
+ let client = !sdk ? await sdkForProject() :
1373
+ sdk;
1374
+ let apiPath = '/tablesdb/{databaseId}/tables/{tableId}/columns/polygon'.replace('{databaseId}', databaseId).replace('{tableId}', tableId);
1375
+ let payload = {};
1376
+ if (typeof key !== 'undefined') {
1377
+ payload['key'] = key;
1378
+ }
1379
+ if (typeof required !== 'undefined') {
1380
+ payload['required'] = required;
1381
+ }
1382
+ if (typeof xdefault !== 'undefined') {
1383
+ payload['default'] = xdefault;
1384
+ }
1385
+
1386
+ let response = undefined;
1387
+
1388
+ response = await client.call('post', apiPath, {
1389
+ 'content-type': 'application/json',
1390
+ }, payload);
1391
+
1392
+ if (parseOutput) {
1393
+ parse(response)
1394
+ }
1395
+
1396
+ return response;
1397
+
1398
+ }
1399
+ /**
1400
+ * @typedef {Object} TablesDBUpdatePolygonColumnRequestParams
1401
+ * @property {string} databaseId Database ID.
1402
+ * @property {string} tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).
1403
+ * @property {string} key Column Key.
1404
+ * @property {boolean} required Is column required?
1405
+ * @property {string} xdefault Default value for column when not provided, as JSON string. Cannot be set when column is required.
1406
+ * @property {string} newKey New Column Key.
1407
+ * @property {boolean} overrideForCli
1408
+ * @property {boolean} parseOutput
1409
+ * @property {libClient | undefined} sdk
1410
+ */
1411
+
1412
+ /**
1413
+ * @param {TablesDBUpdatePolygonColumnRequestParams} params
1414
+ */
1415
+ const tablesDBUpdatePolygonColumn = async ({databaseId,tableId,key,required,xdefault,newKey,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
1416
+ let client = !sdk ? await sdkForProject() :
1417
+ sdk;
1418
+ let apiPath = '/tablesdb/{databaseId}/tables/{tableId}/columns/polygon/{key}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{key}', key);
1419
+ let payload = {};
1420
+ if (typeof required !== 'undefined') {
1421
+ payload['required'] = required;
1422
+ }
1423
+ if (typeof xdefault !== 'undefined') {
1424
+ payload['default'] = xdefault;
1425
+ }
1426
+ if (typeof newKey !== 'undefined') {
1427
+ payload['newKey'] = newKey;
1428
+ }
1429
+
1430
+ let response = undefined;
1431
+
1432
+ response = await client.call('patch', apiPath, {
1433
+ 'content-type': 'application/json',
1434
+ }, payload);
1435
+
1436
+ if (parseOutput) {
1437
+ parse(response)
1438
+ }
1439
+
1440
+ return response;
1441
+
1181
1442
  }
1182
1443
  /**
1183
1444
  * @typedef {Object} TablesDBCreateRelationshipColumnRequestParams
@@ -2566,6 +2827,69 @@ tablesDB
2566
2827
  .option(`--new-key <new-key>`, `New Column Key.`)
2567
2828
  .action(actionRunner(tablesDBUpdateIpColumn))
2568
2829
 
2830
+ tablesDB
2831
+ .command(`create-line-column`)
2832
+ .description(`Create a geometric line attribute.`)
2833
+ .requiredOption(`--database-id <database-id>`, `Database ID.`)
2834
+ .requiredOption(`--table-id <table-id>`, `Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).`)
2835
+ .requiredOption(`--key <key>`, `Column Key.`)
2836
+ .requiredOption(`--required [value]`, `Is column required?`, (value) => value === undefined ? true : parseBool(value))
2837
+ .option(`--xdefault <xdefault>`, `Default value for column when not provided, as JSON string. Cannot be set when column is required.`)
2838
+ .action(actionRunner(tablesDBCreateLineColumn))
2839
+
2840
+ tablesDB
2841
+ .command(`update-line-column`)
2842
+ .description(`Update a line column. Changing the 'default' value will not update already existing documents.`)
2843
+ .requiredOption(`--database-id <database-id>`, `Database ID.`)
2844
+ .requiredOption(`--table-id <table-id>`, `Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).`)
2845
+ .requiredOption(`--key <key>`, `Column Key.`)
2846
+ .requiredOption(`--required [value]`, `Is column required?`, (value) => value === undefined ? true : parseBool(value))
2847
+ .option(`--xdefault <xdefault>`, `Default value for column when not provided, as JSON string. Cannot be set when column is required.`)
2848
+ .option(`--new-key <new-key>`, `New Column Key.`)
2849
+ .action(actionRunner(tablesDBUpdateLineColumn))
2850
+
2851
+ tablesDB
2852
+ .command(`create-point-column`)
2853
+ .description(`Create a geometric point attribute.`)
2854
+ .requiredOption(`--database-id <database-id>`, `Database ID.`)
2855
+ .requiredOption(`--table-id <table-id>`, `Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).`)
2856
+ .requiredOption(`--key <key>`, `Column Key.`)
2857
+ .requiredOption(`--required [value]`, `Is column required?`, (value) => value === undefined ? true : parseBool(value))
2858
+ .option(`--xdefault <xdefault>`, `Default value for column when not provided, as JSON string. Cannot be set when column is required.`)
2859
+ .action(actionRunner(tablesDBCreatePointColumn))
2860
+
2861
+ tablesDB
2862
+ .command(`update-point-column`)
2863
+ .description(`Update a point column. Changing the 'default' value will not update already existing documents.`)
2864
+ .requiredOption(`--database-id <database-id>`, `Database ID.`)
2865
+ .requiredOption(`--table-id <table-id>`, `Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).`)
2866
+ .requiredOption(`--key <key>`, `Column Key.`)
2867
+ .requiredOption(`--required [value]`, `Is column required?`, (value) => value === undefined ? true : parseBool(value))
2868
+ .option(`--xdefault <xdefault>`, `Default value for column when not provided, as JSON string. Cannot be set when column is required.`)
2869
+ .option(`--new-key <new-key>`, `New Column Key.`)
2870
+ .action(actionRunner(tablesDBUpdatePointColumn))
2871
+
2872
+ tablesDB
2873
+ .command(`create-polygon-column`)
2874
+ .description(`Create a geometric polygon attribute.`)
2875
+ .requiredOption(`--database-id <database-id>`, `Database ID.`)
2876
+ .requiredOption(`--table-id <table-id>`, `Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).`)
2877
+ .requiredOption(`--key <key>`, `Column Key.`)
2878
+ .requiredOption(`--required [value]`, `Is column required?`, (value) => value === undefined ? true : parseBool(value))
2879
+ .option(`--xdefault <xdefault>`, `Default value for column when not provided, as JSON string. Cannot be set when column is required.`)
2880
+ .action(actionRunner(tablesDBCreatePolygonColumn))
2881
+
2882
+ tablesDB
2883
+ .command(`update-polygon-column`)
2884
+ .description(`Update a polygon column. Changing the 'default' value will not update already existing documents.`)
2885
+ .requiredOption(`--database-id <database-id>`, `Database ID.`)
2886
+ .requiredOption(`--table-id <table-id>`, `Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate).`)
2887
+ .requiredOption(`--key <key>`, `Column Key.`)
2888
+ .requiredOption(`--required [value]`, `Is column required?`, (value) => value === undefined ? true : parseBool(value))
2889
+ .option(`--xdefault <xdefault>`, `Default value for column when not provided, as JSON string. Cannot be set when column is required.`)
2890
+ .option(`--new-key <new-key>`, `New Column Key.`)
2891
+ .action(actionRunner(tablesDBUpdatePolygonColumn))
2892
+
2569
2893
  tablesDB
2570
2894
  .command(`create-relationship-column`)
2571
2895
  .description(`Create relationship column. [Learn more about relationship columns](https://appwrite.io/docs/databases-relationships#relationship-columns). `)
@@ -2865,6 +3189,12 @@ module.exports = {
2865
3189
  tablesDBUpdateIntegerColumn,
2866
3190
  tablesDBCreateIpColumn,
2867
3191
  tablesDBUpdateIpColumn,
3192
+ tablesDBCreateLineColumn,
3193
+ tablesDBUpdateLineColumn,
3194
+ tablesDBCreatePointColumn,
3195
+ tablesDBUpdatePointColumn,
3196
+ tablesDBCreatePolygonColumn,
3197
+ tablesDBUpdatePolygonColumn,
2868
3198
  tablesDBCreateRelationshipColumn,
2869
3199
  tablesDBCreateStringColumn,
2870
3200
  tablesDBUpdateStringColumn,
@@ -12,6 +12,7 @@ const { Swift } = require("../type-generation/languages/swift");
12
12
  const { Java } = require("../type-generation/languages/java");
13
13
  const { Dart } = require("../type-generation/languages/dart");
14
14
  const { JavaScript } = require("../type-generation/languages/javascript");
15
+ const { CSharp } = require("../type-generation/languages/csharp");
15
16
 
16
17
  /**
17
18
  * @param {string} language
@@ -33,6 +34,8 @@ function createLanguageMeta(language) {
33
34
  return new Java();
34
35
  case "dart":
35
36
  return new Dart();
37
+ case "cs":
38
+ return new CSharp();
36
39
  default:
37
40
  throw new Error(`Language '${language}' is not supported`);
38
41
  }
@@ -55,7 +58,7 @@ const typesLanguageOption = new Option(
55
58
  "-l, --language <language>",
56
59
  "The language of the types"
57
60
  )
58
- .choices(["auto", "ts", "js", "php", "kotlin", "swift", "java", "dart"])
61
+ .choices(["auto", "ts", "js", "php", "kotlin", "swift", "java", "dart", "cs"])
59
62
  .default("auto");
60
63
 
61
64
  const typesStrictOption = new Option(
@@ -97,22 +100,58 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
97
100
  fs.mkdirSync(outputDirectory, { recursive: true });
98
101
  }
99
102
 
100
- const collections = localConfig.getCollections();
101
- if (collections.length === 0) {
102
- const configFileName = path.basename(localConfig.path);
103
- throw new Error(`No collections found in configuration. Make sure ${configFileName} exists and contains collections.`);
103
+ // Try tables first, fallback to collections
104
+ let tables = localConfig.getTables();
105
+ let collections = [];
106
+ let dataSource = 'tables';
107
+
108
+ if (tables.length === 0) {
109
+ collections = localConfig.getCollections();
110
+ dataSource = 'collections';
111
+
112
+ if (collections.length === 0) {
113
+ const configFileName = path.basename(localConfig.path);
114
+ throw new Error(`No tables or collections found in configuration. Make sure ${configFileName} exists and contains tables or collections.`);
115
+ }
116
+ }
117
+
118
+ // Use tables if available, otherwise use collections
119
+ let dataItems = tables.length > 0 ? tables : collections;
120
+ const itemType = tables.length > 0 ? 'tables' : 'collections';
121
+
122
+ // Normalize tables data: rename 'columns' to 'attributes' for template compatibility
123
+ if (tables.length > 0) {
124
+ dataItems = dataItems.map(table => {
125
+ const { columns, ...rest } = table;
126
+ return {
127
+ ...rest,
128
+ attributes: (columns || []).map(column => {
129
+ if (column.relatedTable) {
130
+ const { relatedTable, ...columnRest } = column;
131
+ return {
132
+ ...columnRest,
133
+ relatedCollection: relatedTable
134
+ };
135
+ }
136
+ return column;
137
+ })
138
+ };
139
+ });
104
140
  }
105
141
 
106
- log(`Found ${collections.length} collections: ${collections.map(c => c.name).join(", ")}`);
142
+ log(`Found ${dataItems.length} ${itemType}: ${dataItems.map(c => c.name).join(", ")}`);
143
+
144
+ // Use columns if available, otherwise use attributes
145
+ const resourceType = tables.length > 0 ? 'columns' : 'attributes';
107
146
 
108
- const totalAttributes = collections.reduce((count, collection) => count + collection.attributes.length, 0);
109
- log(`Found ${totalAttributes} attributes across all collections`);
147
+ const totalAttributes = dataItems.reduce((count, item) => count + (item.attributes || []).length, 0);
148
+ log(`Found ${totalAttributes} ${resourceType} across all ${itemType}`);
110
149
 
111
150
  const templater = ejs.compile(meta.getTemplate());
112
151
 
113
152
  if (meta.isSingleFile()) {
114
153
  const content = templater({
115
- collections,
154
+ collections: dataItems,
116
155
  strict,
117
156
  ...templateHelpers,
118
157
  getType: meta.getType,
@@ -123,23 +162,23 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
123
162
  fs.writeFileSync(destination, content);
124
163
  log(`Added types to ${destination}`);
125
164
  } else {
126
- for (const collection of collections) {
165
+ for (const item of dataItems) {
127
166
  const content = templater({
128
- collections,
129
- collection,
167
+ collections: dataItems,
168
+ collection: item,
130
169
  strict,
131
170
  ...templateHelpers,
132
171
  getType: meta.getType,
133
172
  });
134
173
 
135
- const destination = path.join(outputDirectory, meta.getFileName(collection));
174
+ const destination = path.join(outputDirectory, meta.getFileName(item));
136
175
 
137
176
  fs.writeFileSync(destination, content);
138
- log(`Added types for ${collection.name} to ${destination}`);
177
+ log(`Added types for ${item.name} to ${destination}`);
139
178
  }
140
179
  }
141
180
 
142
- success(`Generated types for all the listed collections`);
181
+ success(`Generated types for all the listed ${itemType}`);
143
182
  });
144
183
 
145
184
  const types = new Command("types")
package/lib/config.js CHANGED
@@ -55,7 +55,7 @@ const KeysColumns = new Set([
55
55
  // enum
56
56
  "elements",
57
57
  // relationship
58
- "relatedCollection",
58
+ "relatedTable",
59
59
  "relationType",
60
60
  "twoWay",
61
61
  "twoWayKey",
@@ -150,6 +150,47 @@ class Config {
150
150
  toString() {
151
151
  return JSONbig.stringify(this.data, null, 4);
152
152
  }
153
+
154
+ _getDBEntities(entityType) {
155
+ if (!this.has(entityType)) {
156
+ return [];
157
+ }
158
+ return this.get(entityType);
159
+ }
160
+
161
+ _getDBEntity(entityType, $id) {
162
+ if (!this.has(entityType)) {
163
+ return {};
164
+ }
165
+
166
+ let entities = this.get(entityType);
167
+ for (let i = 0; i < entities.length; i++) {
168
+ if (entities[i]['$id'] == $id) {
169
+ return entities[i];
170
+ }
171
+ }
172
+
173
+ return {};
174
+ }
175
+
176
+ _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
177
+ props = whitelistKeys(props, keysSet, nestedKeys);
178
+
179
+ if (!this.has(entityType)) {
180
+ this.set(entityType, []);
181
+ }
182
+
183
+ let entities = this.get(entityType);
184
+ for (let i = 0; i < entities.length; i++) {
185
+ if (entities[i]['$id'] == props['$id']) {
186
+ entities[i] = props;
187
+ this.set(entityType, entities);
188
+ return;
189
+ }
190
+ }
191
+ entities.push(props);
192
+ this.set(entityType, entities);
193
+ }
153
194
  }
154
195
 
155
196
  class Local extends Config {
@@ -464,45 +505,28 @@ class Local extends Config {
464
505
  this.set("topics", topics);
465
506
  }
466
507
 
467
- getDatabases() {
468
- if (!this.has("databases")) {
469
- return [];
470
- }
471
- return this.get("databases");
508
+ getTablesDBs() {
509
+ return this._getDBEntities("tablesDB");
472
510
  }
473
511
 
474
- getDatabase($id) {
475
- if (!this.has("databases")) {
476
- return {};
477
- }
512
+ getTablesDB($id) {
513
+ return this._getDBEntity("tablesDB", $id);
514
+ }
515
+
516
+ addTablesDB(props) {
517
+ this._addDBEntity("tablesDB", props, KeysDatabase);
518
+ }
478
519
 
479
- let databases = this.get("databases");
480
- for (let i = 0; i < databases.length; i++) {
481
- if (databases[i]['$id'] == $id) {
482
- return databases[i];
483
- }
484
- }
520
+ getDatabases() {
521
+ return this._getDBEntities("databases");
522
+ }
485
523
 
486
- return {};
524
+ getDatabase($id) {
525
+ return this._getDBEntity("databases", $id);
487
526
  }
488
527
 
489
528
  addDatabase(props) {
490
- props = whitelistKeys(props, KeysDatabase);
491
-
492
- if (!this.has("databases")) {
493
- this.set("databases", []);
494
- }
495
-
496
- let databases = this.get("databases");
497
- for (let i = 0; i < databases.length; i++) {
498
- if (databases[i]['$id'] == props['$id']) {
499
- databases[i] = props;
500
- this.set("databases", databases);
501
- return;
502
- }
503
- }
504
- databases.push(props);
505
- this.set("databases", databases);
529
+ this._addDBEntity("databases", props, KeysDatabase);
506
530
  }
507
531
 
508
532
  getTeams() {