(packs: Pack[], tables: (DBTable | string)[], getLocs?: boolean)
| 757 | return amendedSchemaFields; |
| 758 | }; |
| 759 | export const getPacksTableData = (packs: Pack[], tables: (DBTable | string)[], getLocs?: boolean) => { |
| 760 | console.log( |
| 761 | "getPacksTableData:", |
| 762 | packs.map((pack) => pack.name), |
| 763 | "num tables:", |
| 764 | tables.length, |
| 765 | ); |
| 766 | // console.log( |
| 767 | // "getPacksTableData:", |
| 768 | // packs.map((pack) => pack.name), |
| 769 | // tables |
| 770 | // ); |
| 771 | const results: PackViewData[] = []; |
| 772 | for (const pack of packs) { |
| 773 | const locFiles: Record<string, PackedFile> = {}; |
| 774 | if (getLocs) { |
| 775 | for (const packedFile of pack.packedFiles) { |
| 776 | if (packedFile.name.endsWith(".loc")) { |
| 777 | // console.log("found loc pack file", packedFile.name); |
| 778 | locFiles[packedFile.name] = packedFile; |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | const result = { packName: pack.name, packPath: pack.path, tables } as PackViewData; |
| 783 | result.packedFiles = result.packedFiles || {}; |
| 784 | let packedFiles: PackedFile[] = []; |
| 785 | if (getLocs) { |
| 786 | packedFiles = packedFiles.concat(Object.values(locFiles)); |
| 787 | } |
| 788 | for (const table of tables) { |
| 789 | if (typeof table === "string") { |
| 790 | packedFiles = pack.packedFiles.filter((packedFile) => packedFile.name.startsWith(table)); |
| 791 | } else { |
| 792 | packedFiles = pack.packedFiles.filter((packedFile) => |
| 793 | packedFile.name.startsWith(`db\\${table.dbName}\\${table.dbSubname}`), |
| 794 | ); |
| 795 | } |
| 796 | // console.log("getpackviewdata packedFiles:", packedFiles); |
| 797 | for (const packedFile of packedFiles) { |
| 798 | const amendedSchemaFields: AmendedSchemaField[] = []; |
| 799 | const dbversion = locFiles[packedFile.name] ? LocVersion : getDBVersion(packedFile); |
| 800 | if (!dbversion) { |
| 801 | console.log("no dbversion for", packedFile.name); |
| 802 | return; |
| 803 | } |
| 804 | const chunkedSchemaIntoRows = chunkSchemaIntoRows(packedFile.schemaFields || [], dbversion); |
| 805 | // console.log("chunked into ", chunkedSchemaIntoRows.length); |
| 806 | // console.log("num fields in row is ", dbversion.fields.length); |
| 807 | // console.log("db types are ", dbversion.fields.map((field) => field.name).join(", ")); |
| 808 | // console.log("with num chunks of ", chunkedSchemaIntoRows.map((row) => row.length).join(",")); |
| 809 | for (const chunkedSchemaIntoRow of chunkedSchemaIntoRows) { |
| 810 | for (const dbFieldsIndex of dbversion.fields.keys()) { |
| 811 | const { name, field_type } = dbversion.fields[dbFieldsIndex]; |
| 812 | const fields = chunkedSchemaIntoRow[dbFieldsIndex].fields; |
| 813 | if (!fields) { |
| 814 | console.log("MISSING FIELD ", name); |
| 815 | } |
| 816 | const resolvedKeyValue = resolveKeyValue(field_type, fields); |
no test coverage detected