(pack: Pack, table?: DBTable | string, getLocs?: boolean)
| 833 | return results; |
| 834 | }; |
| 835 | export const getPackViewData = (pack: Pack, table?: DBTable | string, getLocs?: boolean) => { |
| 836 | console.log("getPackViewData:", pack.name, table); |
| 837 | const tables = pack.packedFiles.map((packedFile) => packedFile.name); |
| 838 | const locFiles: Record<string, PackedFile> = {}; |
| 839 | if (getLocs) { |
| 840 | for (const packedFile of pack.packedFiles) { |
| 841 | if (packedFile.name.endsWith(".loc")) { |
| 842 | // console.log("found loc pack file", packedFile.name); |
| 843 | locFiles[packedFile.name] = packedFile; |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | const result = { packName: pack.name, packPath: pack.path, tables } as PackViewData; |
| 848 | result.packedFiles = result.packedFiles || {}; |
| 849 | let packedFiles: PackedFile[] = []; |
| 850 | if (table) { |
| 851 | if (typeof table === "string") { |
| 852 | packedFiles = pack.packedFiles.filter((packedFile) => packedFile.name == table); |
| 853 | } else { |
| 854 | packedFiles = pack.packedFiles.filter((packedFile) => |
| 855 | packedFile.name.startsWith(`db\\${table.dbName}\\${table.dbSubname}`), |
| 856 | ); |
| 857 | } |
| 858 | } |
| 859 | if (getLocs) { |
| 860 | packedFiles = packedFiles.concat(Object.values(locFiles)); |
| 861 | } |
| 862 | // console.log("getpackviewdata packedFiles:", packedFiles); |
| 863 | for (const packedFile of packedFiles) { |
| 864 | const amendedSchemaFields: AmendedSchemaField[] = []; |
| 865 | const dbversion = locFiles[packedFile.name] ? LocVersion : getDBVersion(packedFile); |
| 866 | if (!dbversion) { |
| 867 | console.log("no dbversion for", packedFile.name); |
| 868 | return; |
| 869 | } |
| 870 | const chunkedSchemaIntoRows = chunkSchemaIntoRows(packedFile.schemaFields || [], dbversion); |
| 871 | // console.log("chunked into ", chunkedSchemaIntoRows.length); |
| 872 | // console.log("num fields in row is ", dbversion.fields.length); |
| 873 | // console.log("db types are ", dbversion.fields.map((field) => field.name).join(", ")); |
| 874 | // console.log("with num chunks of ", chunkedSchemaIntoRows.map((row) => row.length).join(",")); |
| 875 | for (const chunkedSchemaIntoRow of chunkedSchemaIntoRows) { |
| 876 | for (const dbFieldsIndex of dbversion.fields.keys()) { |
| 877 | const { name, field_type } = dbversion.fields[dbFieldsIndex]; |
| 878 | const fields = chunkedSchemaIntoRow[dbFieldsIndex].fields; |
| 879 | if (!fields) { |
| 880 | console.log("MISSING FIELD ", name); |
| 881 | } |
| 882 | const resolvedKeyValue = resolveKeyValue(field_type, fields); |
| 883 | amendedSchemaFields.push({ name, resolvedKeyValue, ...chunkedSchemaIntoRow[dbFieldsIndex] }); |
| 884 | // if (chunkedSchemaIntoRow == chunkedSchemaIntoRows[0]) { |
| 885 | // console.log("AMENDING ", name, resolvedKeyValue); |
| 886 | // } |
| 887 | } |
| 888 | } |
| 889 | packedFile.schemaFields = amendedSchemaFields; |
| 890 | packedFile.tableSchema = dbversion; |
| 891 | result.packedFiles[packedFile.name] = packedFile; |
| 892 | } |
no test coverage detected