@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 7.84 kB
Source Map (JSON)
{"version":3,"file":"document-table.mjs","names":[],"sources":["../../../../../src/libs/collection/schema/tables/document-table.ts"],"sourcesContent":["import type CollectionBuilder from \"../../../../libs/collection/builders/collection-builder/index.js\";\nimport type DatabaseAdapter from \"../../../../libs/db/adapter-base.js\";\nimport type { ServiceResponse } from \"../../../../types.js\";\nimport buildSchemaIndex from \"../../helpers/build-schema-index.js\";\nimport buildTableName from \"../../helpers/build-table-name.js\";\nimport type { CollectionSchemaTable } from \"../types.js\";\n\n/**\n * Returns the document table\n */\nconst createDocumentTable = (props: {\n\tcollection: CollectionBuilder;\n\tdb: DatabaseAdapter;\n}): Awaited<\n\tServiceResponse<{\n\t\tschema: CollectionSchemaTable;\n\t}>\n> => {\n\tconst tableNameRes = buildTableName(\n\t\t\"document\",\n\t\t{\n\t\t\tcollection: props.collection.key,\n\t\t},\n\t\tprops.db.config.tableNameByteLimit,\n\t);\n\tif (tableNameRes.error) return tableNameRes;\n\tconst tableName = tableNameRes.data.name;\n\n\treturn {\n\t\tdata: {\n\t\t\tschema: {\n\t\t\t\tname: tableName,\n\t\t\t\trawName: tableNameRes.data.rawName,\n\t\t\t\ttype: \"document\",\n\t\t\t\tkey: {\n\t\t\t\t\tcollection: props.collection.key,\n\t\t\t\t},\n\t\t\t\tcolumns: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"id\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"primary\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tprimary: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"collection_key\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"text\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_collections\",\n\t\t\t\t\t\t\tcolumn: \"key\",\n\t\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"collection_migration_id\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_collection_migrations\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"restrict\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"tenant_key\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"text\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"order\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"text\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"is_deleted\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"boolean\"),\n\t\t\t\t\t\tdefault: props.db.getDefault(\"boolean\", \"false\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"is_deleted_at\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"timestamp\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"deleted_by\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_users\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"set null\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"created_by\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_users\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"set null\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"created_at\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"timestamp\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tdefault: props.db.getDefault(\"timestamp\", \"now\"),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"updated_by\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_users\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"set null\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"updated_at\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"timestamp\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tdefault: props.db.getDefault(\"timestamp\", \"now\"),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tindexes: [\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"tenant_key\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"order\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"is_deleted\", \"updated_at\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"is_deleted\", \"created_at\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"created_by\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"updated_by\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"deleted_by\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\terror: undefined,\n\t};\n};\n\nexport default createDocumentTable;\n"],"mappings":"sGAUA,MAAM,EAAuB,GAOxB,CACJ,IAAM,EAAe,EACpB,WACA,CACC,WAAY,EAAM,WAAW,GAC9B,EACA,EAAM,GAAG,OAAO,kBACjB,EACA,GAAI,EAAa,MAAO,OAAO,EAC/B,IA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