@jrmc/adonis-attachment 5.2.1 → 6.0.0-alpha.1
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/README.md +10 -81
- package/build/bin/test.d.ts +2 -0
- package/build/bin/test.d.ts.map +1 -0
- package/build/bin/test.js +9 -0
- package/build/bin/test.js.map +1 -0
- package/build/commands/commands.json +1 -1
- package/build/commands/make/attachment_v5_migration.d.ts +17 -0
- package/build/commands/make/attachment_v5_migration.d.ts.map +1 -0
- package/build/commands/make/attachment_v5_migration.js +26 -0
- package/build/commands/make/attachment_v5_migration.js.map +1 -0
- package/build/commands/make/{converter.d.ts → attachments_table.d.ts} +6 -4
- package/build/commands/make/attachments_table.d.ts.map +1 -0
- package/build/commands/make/attachments_table.js +30 -0
- package/build/commands/make/attachments_table.js.map +1 -0
- package/build/configure.d.ts.map +1 -1
- package/build/configure.js +2 -1
- package/build/configure.js.map +1 -0
- package/build/index.d.ts +26 -10
- package/build/index.d.ts.map +1 -1
- package/build/index.js +16 -9
- package/build/index.js.map +1 -0
- package/build/providers/attachment_provider.d.ts +0 -19
- package/build/providers/attachment_provider.d.ts.map +1 -1
- package/build/providers/attachment_provider.js +30 -26
- package/build/providers/attachment_provider.js.map +1 -0
- package/build/services/main.d.ts +3 -3
- package/build/services/main.d.ts.map +1 -1
- package/build/services/main.js +42 -5
- package/build/services/main.js.map +1 -0
- package/build/src/adapters/adonis_drive_storage.d.ts +33 -0
- package/build/src/adapters/adonis_drive_storage.d.ts.map +1 -0
- package/build/src/adapters/adonis_drive_storage.js +35 -0
- package/build/src/adapters/adonis_drive_storage.js.map +1 -0
- package/build/src/adapters/local_file_storage.d.ts +25 -0
- package/build/src/adapters/local_file_storage.d.ts.map +1 -0
- package/build/src/adapters/local_file_storage.js +54 -0
- package/build/src/adapters/local_file_storage.js.map +1 -0
- package/build/src/controllers/attachments_controller.d.ts +13 -2
- package/build/src/controllers/attachments_controller.d.ts.map +1 -1
- package/build/src/controllers/attachments_controller.js +20 -107
- package/build/src/controllers/attachments_controller.js.map +1 -0
- package/build/src/core/attachment.d.ts +70 -0
- package/build/src/core/attachment.d.ts.map +1 -0
- package/build/src/core/attachment.js +150 -0
- package/build/src/core/attachment.js.map +1 -0
- package/build/src/core/attachment_job_processor.d.ts +30 -0
- package/build/src/core/attachment_job_processor.d.ts.map +1 -0
- package/build/src/core/attachment_job_processor.js +47 -0
- package/build/src/core/attachment_job_processor.js.map +1 -0
- package/build/src/core/attachment_options.d.ts +32 -0
- package/build/src/core/attachment_options.d.ts.map +1 -0
- package/build/src/core/attachment_options.js +24 -0
- package/build/src/core/attachment_options.js.map +1 -0
- package/build/src/core/attachment_repository.d.ts +15 -0
- package/build/src/core/attachment_repository.d.ts.map +1 -0
- package/build/src/core/attachment_repository.js +8 -0
- package/build/src/core/attachment_repository.js.map +1 -0
- package/build/src/core/attachment_service.d.ts +34 -0
- package/build/src/core/attachment_service.d.ts.map +1 -0
- package/build/src/core/attachment_service.js +93 -0
- package/build/src/core/attachment_service.js.map +1 -0
- package/build/src/core/attachment_state.d.ts +11 -0
- package/build/src/core/attachment_state.d.ts.map +1 -0
- package/build/src/core/attachment_state.js +17 -0
- package/build/src/core/attachment_state.js.map +1 -0
- package/build/src/core/index.d.ts +14 -0
- package/build/src/core/index.d.ts.map +1 -0
- package/build/src/core/index.js +11 -0
- package/build/src/core/index.js.map +1 -0
- package/build/src/core/queue.d.ts +20 -0
- package/build/src/core/queue.d.ts.map +1 -0
- package/build/src/{types/event.js → core/queue.js} +1 -0
- package/build/src/core/queue.js.map +1 -0
- package/build/src/core/storage.d.ts +23 -0
- package/build/src/core/storage.d.ts.map +1 -0
- package/build/src/{types/config.js → core/storage.js} +1 -0
- package/build/src/core/storage.js.map +1 -0
- package/build/src/define_config.d.ts +39 -20
- package/build/src/define_config.d.ts.map +1 -1
- package/build/src/define_config.js +46 -24
- package/build/src/define_config.js.map +1 -0
- package/build/src/integrations/lucid/attachment_column.d.ts +18 -0
- package/build/src/integrations/lucid/attachment_column.d.ts.map +1 -0
- package/build/src/integrations/lucid/attachment_column.js +151 -0
- package/build/src/integrations/lucid/attachment_column.js.map +1 -0
- package/build/src/integrations/lucid/attachment_model.d.ts +37 -0
- package/build/src/integrations/lucid/attachment_model.d.ts.map +1 -0
- package/build/src/integrations/lucid/attachment_model.js +99 -0
- package/build/src/integrations/lucid/attachment_model.js.map +1 -0
- package/build/src/integrations/lucid/attachment_owner.d.ts +18 -0
- package/build/src/integrations/lucid/attachment_owner.d.ts.map +1 -0
- package/build/src/integrations/lucid/attachment_owner.js +15 -0
- package/build/src/integrations/lucid/attachment_owner.js.map +1 -0
- package/build/src/integrations/lucid/attachment_relation.d.ts +60 -0
- package/build/src/integrations/lucid/attachment_relation.d.ts.map +1 -0
- package/build/src/integrations/lucid/attachment_relation.js +163 -0
- package/build/src/integrations/lucid/attachment_relation.js.map +1 -0
- package/build/src/integrations/lucid/attachments_table_stub.d.ts +21 -0
- package/build/src/integrations/lucid/attachments_table_stub.d.ts.map +1 -0
- package/build/src/integrations/lucid/attachments_table_stub.js +26 -0
- package/build/src/integrations/lucid/attachments_table_stub.js.map +1 -0
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts +13 -0
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts.map +1 -0
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js +20 -0
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js.map +1 -0
- package/build/src/integrations/lucid/index.d.ts +20 -0
- package/build/src/integrations/lucid/index.d.ts.map +1 -0
- package/build/src/integrations/lucid/index.js +20 -0
- package/build/src/integrations/lucid/index.js.map +1 -0
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts +30 -0
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +1 -0
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js +188 -0
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +1 -0
- package/build/src/integrations/lucid/lucid_attachment_repository.d.ts +18 -0
- package/build/src/integrations/lucid/lucid_attachment_repository.d.ts.map +1 -0
- package/build/src/integrations/lucid/lucid_attachment_repository.js +21 -0
- package/build/src/integrations/lucid/lucid_attachment_repository.js.map +1 -0
- package/build/src/integrations/lucid/lucid_attachment_store.d.ts +36 -0
- package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +1 -0
- package/build/src/integrations/lucid/lucid_attachment_store.js +179 -0
- package/build/src/integrations/lucid/lucid_attachment_store.js.map +1 -0
- package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts +24 -0
- package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts.map +1 -0
- package/build/src/integrations/lucid/lucid_variant_generation_service.js +42 -0
- package/build/src/integrations/lucid/lucid_variant_generation_service.js.map +1 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts +64 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +1 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment.js +89 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +1 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts +34 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts.map +1 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment_records.js +47 -0
- package/build/src/integrations/lucid/migrate_legacy_attachment_records.js.map +1 -0
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts +11 -0
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts.map +1 -0
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js +41 -0
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js.map +1 -0
- package/build/src/queues/adonis_queue.d.ts +27 -0
- package/build/src/queues/adonis_queue.d.ts.map +1 -0
- package/build/src/queues/adonis_queue.js +22 -0
- package/build/src/queues/adonis_queue.js.map +1 -0
- package/build/src/queues/memory_queue.d.ts +22 -0
- package/build/src/queues/memory_queue.d.ts.map +1 -0
- package/build/src/queues/memory_queue.js +67 -0
- package/build/src/queues/memory_queue.js.map +1 -0
- package/build/src/sources/attachment_manager.d.ts +53 -0
- package/build/src/sources/attachment_manager.d.ts.map +1 -0
- package/build/src/sources/attachment_manager.js +177 -0
- package/build/src/sources/attachment_manager.js.map +1 -0
- package/build/src/variants/variant_converter.d.ts +23 -0
- package/build/src/variants/variant_converter.d.ts.map +1 -0
- package/build/src/{types/converter.js → variants/variant_converter.js} +1 -0
- package/build/src/variants/variant_converter.js.map +1 -0
- package/build/src/variants/variant_generation_service.d.ts +28 -0
- package/build/src/variants/variant_generation_service.d.ts.map +1 -0
- package/build/src/variants/variant_generation_service.js +44 -0
- package/build/src/variants/variant_generation_service.js.map +1 -0
- package/build/stubs/config/attachment.stub +12 -0
- package/build/stubs/main.d.ts.map +1 -1
- package/build/stubs/main.js +1 -0
- package/build/stubs/main.js.map +1 -0
- package/build/stubs/migrations/attachments_table.stub +39 -0
- package/build/tests/adonis_drive_storage.spec.d.ts +8 -0
- package/build/tests/adonis_drive_storage.spec.d.ts.map +1 -0
- package/build/tests/adonis_drive_storage.spec.js +69 -0
- package/build/tests/adonis_drive_storage.spec.js.map +1 -0
- package/build/{src/types/attachment.js → tests/adonis_queue.spec.d.ts} +1 -0
- package/build/tests/adonis_queue.spec.d.ts.map +1 -0
- package/build/tests/adonis_queue.spec.js +52 -0
- package/build/tests/adonis_queue.spec.js.map +1 -0
- package/build/tests/attachment_job_processor.spec.d.ts +8 -0
- package/build/tests/attachment_job_processor.spec.d.ts.map +1 -0
- package/build/tests/attachment_job_processor.spec.js +89 -0
- package/build/tests/attachment_job_processor.spec.js.map +1 -0
- package/build/tests/attachment_manager.spec.d.ts +8 -0
- package/build/tests/attachment_manager.spec.d.ts.map +1 -0
- package/build/tests/attachment_manager.spec.js +131 -0
- package/build/tests/attachment_manager.spec.js.map +1 -0
- package/build/tests/attachment_manager_service.spec.d.ts +8 -0
- package/build/tests/attachment_manager_service.spec.d.ts.map +1 -0
- package/build/tests/attachment_manager_service.spec.js +47 -0
- package/build/tests/attachment_manager_service.spec.js.map +1 -0
- package/build/tests/attachment_options.spec.d.ts +2 -0
- package/build/tests/attachment_options.spec.d.ts.map +1 -0
- package/build/tests/attachment_options.spec.js +31 -0
- package/build/tests/attachment_options.spec.js.map +1 -0
- package/build/tests/attachment_provider.spec.d.ts +8 -0
- package/build/tests/attachment_provider.spec.d.ts.map +1 -0
- package/build/tests/attachment_provider.spec.js +71 -0
- package/build/tests/attachment_provider.spec.js.map +1 -0
- package/build/tests/attachment_service.spec.d.ts +8 -0
- package/build/tests/attachment_service.spec.d.ts.map +1 -0
- package/build/tests/attachment_service.spec.js +146 -0
- package/build/tests/attachment_service.spec.js.map +1 -0
- package/build/tests/attachments_controller.spec.d.ts +8 -0
- package/build/tests/attachments_controller.spec.d.ts.map +1 -0
- package/build/tests/attachments_controller.spec.js +34 -0
- package/build/tests/attachments_controller.spec.js.map +1 -0
- package/build/tests/attachments_table_stub.spec.d.ts +2 -0
- package/build/tests/attachments_table_stub.spec.d.ts.map +1 -0
- package/build/tests/attachments_table_stub.spec.js +66 -0
- package/build/tests/attachments_table_stub.spec.js.map +1 -0
- package/build/tests/configure.spec.d.ts +2 -0
- package/build/tests/configure.spec.d.ts.map +1 -0
- package/build/tests/configure.spec.js +38 -0
- package/build/tests/configure.spec.js.map +1 -0
- package/build/tests/container_bindings.types.d.ts +8 -0
- package/build/tests/container_bindings.types.d.ts.map +1 -0
- package/build/tests/container_bindings.types.js +9 -0
- package/build/tests/container_bindings.types.js.map +1 -0
- package/build/tests/create_legacy_attachment_migration_script.spec.d.ts +8 -0
- package/build/tests/create_legacy_attachment_migration_script.spec.d.ts.map +1 -0
- package/build/tests/create_legacy_attachment_migration_script.spec.js +31 -0
- package/build/tests/create_legacy_attachment_migration_script.spec.js.map +1 -0
- package/build/tests/define_config.spec.d.ts +8 -0
- package/build/tests/define_config.spec.d.ts.map +1 -0
- package/build/tests/define_config.spec.js +203 -0
- package/build/tests/define_config.spec.js.map +1 -0
- package/build/tests/helpers/lucid_test_database.d.ts +9 -0
- package/build/tests/helpers/lucid_test_database.d.ts.map +1 -0
- package/build/tests/helpers/lucid_test_database.js +52 -0
- package/build/tests/helpers/lucid_test_database.js.map +1 -0
- package/build/tests/local_file_storage.spec.d.ts +8 -0
- package/build/tests/local_file_storage.spec.d.ts.map +1 -0
- package/build/tests/local_file_storage.spec.js +44 -0
- package/build/tests/local_file_storage.spec.js.map +1 -0
- package/build/tests/lucid_attachment_collection_store.spec.d.ts +2 -0
- package/build/tests/lucid_attachment_collection_store.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_collection_store.spec.js +52 -0
- package/build/tests/lucid_attachment_collection_store.spec.js.map +1 -0
- package/build/tests/lucid_attachment_column.spec.d.ts +8 -0
- package/build/tests/lucid_attachment_column.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_column.spec.js +193 -0
- package/build/tests/lucid_attachment_column.spec.js.map +1 -0
- package/build/tests/lucid_attachment_lifecycle_service.spec.d.ts +8 -0
- package/build/tests/lucid_attachment_lifecycle_service.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_lifecycle_service.spec.js +378 -0
- package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -0
- package/build/tests/lucid_attachment_relation.spec.d.ts +8 -0
- package/build/tests/lucid_attachment_relation.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_relation.spec.js +216 -0
- package/build/tests/lucid_attachment_relation.spec.js.map +1 -0
- package/build/tests/lucid_attachment_repository.spec.d.ts +8 -0
- package/build/tests/lucid_attachment_repository.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_repository.spec.js +50 -0
- package/build/tests/lucid_attachment_repository.spec.js.map +1 -0
- package/build/tests/lucid_attachment_store.spec.d.ts +8 -0
- package/build/tests/lucid_attachment_store.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_store.spec.js +73 -0
- package/build/tests/lucid_attachment_store.spec.js.map +1 -0
- package/build/tests/lucid_sqlite_integration.spec.d.ts +8 -0
- package/build/tests/lucid_sqlite_integration.spec.d.ts.map +1 -0
- package/build/tests/lucid_sqlite_integration.spec.js +103 -0
- package/build/tests/lucid_sqlite_integration.spec.js.map +1 -0
- package/build/tests/lucid_variant_generation_service.spec.d.ts +8 -0
- package/build/tests/lucid_variant_generation_service.spec.d.ts.map +1 -0
- package/build/tests/lucid_variant_generation_service.spec.js +56 -0
- package/build/tests/lucid_variant_generation_service.spec.js.map +1 -0
- package/build/tests/memory_queue.spec.d.ts +8 -0
- package/build/tests/memory_queue.spec.d.ts.map +1 -0
- package/build/tests/memory_queue.spec.js +52 -0
- package/build/tests/memory_queue.spec.js.map +1 -0
- package/build/tests/migrate_legacy_attachment.spec.d.ts +8 -0
- package/build/tests/migrate_legacy_attachment.spec.d.ts.map +1 -0
- package/build/tests/migrate_legacy_attachment.spec.js +133 -0
- package/build/tests/migrate_legacy_attachment.spec.js.map +1 -0
- package/build/tests/migrate_legacy_attachment_records.spec.d.ts +8 -0
- package/build/tests/migrate_legacy_attachment_records.spec.d.ts.map +1 -0
- package/build/tests/migrate_legacy_attachment_records.spec.js +66 -0
- package/build/tests/migrate_legacy_attachment_records.spec.js.map +1 -0
- package/build/tests/package_exports.spec.d.ts +8 -0
- package/build/tests/package_exports.spec.d.ts.map +1 -0
- package/build/tests/package_exports.spec.js +31 -0
- package/build/tests/package_exports.spec.js.map +1 -0
- package/build/tests/variant_generation_service.spec.d.ts +8 -0
- package/build/tests/variant_generation_service.spec.d.ts.map +1 -0
- package/build/tests/variant_generation_service.spec.js +79 -0
- package/build/tests/variant_generation_service.spec.js.map +1 -0
- package/package.json +82 -76
- package/build/commands/make/converter.d.ts.map +0 -1
- package/build/commands/make/converter.js +0 -28
- package/build/services/regenerate_service.d.ts +0 -9
- package/build/services/regenerate_service.d.ts.map +0 -1
- package/build/services/regenerate_service.js +0 -29
- package/build/src/adapters/blurhash.d.ts +0 -11
- package/build/src/adapters/blurhash.d.ts.map +0 -1
- package/build/src/adapters/blurhash.js +0 -12
- package/build/src/adapters/exif.d.ts +0 -15
- package/build/src/adapters/exif.d.ts.map +0 -1
- package/build/src/adapters/exif.js +0 -165
- package/build/src/adapters/ffmpeg.d.ts +0 -19
- package/build/src/adapters/ffmpeg.d.ts.map +0 -1
- package/build/src/adapters/ffmpeg.js +0 -115
- package/build/src/adapters/lock.d.ts +0 -9
- package/build/src/adapters/lock.d.ts.map +0 -1
- package/build/src/adapters/lock.js +0 -21
- package/build/src/adapters/meta.d.ts +0 -10
- package/build/src/adapters/meta.d.ts.map +0 -1
- package/build/src/adapters/meta.js +0 -49
- package/build/src/adapters/poppler.d.ts +0 -20
- package/build/src/adapters/poppler.d.ts.map +0 -1
- package/build/src/adapters/poppler.js +0 -117
- package/build/src/adapters/soffice.d.ts +0 -14
- package/build/src/adapters/soffice.d.ts.map +0 -1
- package/build/src/adapters/soffice.js +0 -64
- package/build/src/attachment_manager.d.ts +0 -50
- package/build/src/attachment_manager.d.ts.map +0 -1
- package/build/src/attachment_manager.js +0 -145
- package/build/src/attachments/attachment.d.ts +0 -42
- package/build/src/attachments/attachment.d.ts.map +0 -1
- package/build/src/attachments/attachment.js +0 -233
- package/build/src/attachments/attachment_base.d.ts +0 -59
- package/build/src/attachments/attachment_base.d.ts.map +0 -1
- package/build/src/attachments/attachment_base.js +0 -211
- package/build/src/attachments/variant_attachment.d.ts +0 -27
- package/build/src/attachments/variant_attachment.d.ts.map +0 -1
- package/build/src/attachments/variant_attachment.js +0 -40
- package/build/src/converters/autodetect_converter.d.ts +0 -13
- package/build/src/converters/autodetect_converter.d.ts.map +0 -1
- package/build/src/converters/autodetect_converter.js +0 -77
- package/build/src/converters/converter.d.ts +0 -14
- package/build/src/converters/converter.d.ts.map +0 -1
- package/build/src/converters/converter.js +0 -14
- package/build/src/converters/document_thumbnail_converter.d.ts +0 -14
- package/build/src/converters/document_thumbnail_converter.d.ts.map +0 -1
- package/build/src/converters/document_thumbnail_converter.js +0 -36
- package/build/src/converters/image_converter.d.ts +0 -13
- package/build/src/converters/image_converter.d.ts.map +0 -1
- package/build/src/converters/image_converter.js +0 -27
- package/build/src/converters/pdf_thumbnail_converter.d.ts +0 -14
- package/build/src/converters/pdf_thumbnail_converter.d.ts.map +0 -1
- package/build/src/converters/pdf_thumbnail_converter.js +0 -39
- package/build/src/converters/video_thumbnail_converter.d.ts +0 -14
- package/build/src/converters/video_thumbnail_converter.d.ts.map +0 -1
- package/build/src/converters/video_thumbnail_converter.js +0 -40
- package/build/src/decorators/attachment.d.ts +0 -15
- package/build/src/decorators/attachment.d.ts.map +0 -1
- package/build/src/decorators/attachment.js +0 -103
- package/build/src/errors.d.ts +0 -67
- package/build/src/errors.d.ts.map +0 -1
- package/build/src/errors.js +0 -68
- package/build/src/services/attachment/attachment_detachment_service.d.ts +0 -19
- package/build/src/services/attachment/attachment_detachment_service.d.ts.map +0 -1
- package/build/src/services/attachment/attachment_detachment_service.js +0 -66
- package/build/src/services/attachment/attachment_persister_service.d.ts +0 -22
- package/build/src/services/attachment/attachment_persister_service.d.ts.map +0 -1
- package/build/src/services/attachment/attachment_persister_service.js +0 -96
- package/build/src/services/attachment/attachment_recorder_service.d.ts +0 -68
- package/build/src/services/attachment/attachment_recorder_service.d.ts.map +0 -1
- package/build/src/services/attachment/attachment_recorder_service.js +0 -121
- package/build/src/services/attachment/attachment_transaction_service.d.ts +0 -26
- package/build/src/services/attachment/attachment_transaction_service.d.ts.map +0 -1
- package/build/src/services/attachment/attachment_transaction_service.js +0 -46
- package/build/src/services/attachment/attachment_utils.d.ts +0 -35
- package/build/src/services/attachment/attachment_utils.d.ts.map +0 -1
- package/build/src/services/attachment/attachment_utils.js +0 -71
- package/build/src/services/attachment/attachment_variant_service.d.ts +0 -17
- package/build/src/services/attachment/attachment_variant_service.d.ts.map +0 -1
- package/build/src/services/attachment/attachment_variant_service.js +0 -99
- package/build/src/services/attachment/index.d.ts +0 -15
- package/build/src/services/attachment/index.d.ts.map +0 -1
- package/build/src/services/attachment/index.js +0 -15
- package/build/src/services/attachment_service.d.ts +0 -8
- package/build/src/services/attachment_service.d.ts.map +0 -1
- package/build/src/services/attachment_service.js +0 -7
- package/build/src/services/variant/variant_generator_service.d.ts +0 -24
- package/build/src/services/variant/variant_generator_service.d.ts.map +0 -1
- package/build/src/services/variant/variant_generator_service.js +0 -101
- package/build/src/services/variant/variant_persister_service.d.ts +0 -24
- package/build/src/services/variant/variant_persister_service.d.ts.map +0 -1
- package/build/src/services/variant/variant_persister_service.js +0 -59
- package/build/src/services/variant/variant_purger_service.d.ts +0 -15
- package/build/src/services/variant/variant_purger_service.d.ts.map +0 -1
- package/build/src/services/variant/variant_purger_service.js +0 -47
- package/build/src/services/variant_service.d.ts +0 -13
- package/build/src/services/variant_service.d.ts.map +0 -1
- package/build/src/services/variant_service.js +0 -63
- package/build/src/types/attachment.d.ts +0 -100
- package/build/src/types/attachment.d.ts.map +0 -1
- package/build/src/types/config.d.ts +0 -58
- package/build/src/types/config.d.ts.map +0 -1
- package/build/src/types/converter.d.ts +0 -144
- package/build/src/types/converter.d.ts.map +0 -1
- package/build/src/types/drive.d.ts +0 -6
- package/build/src/types/drive.d.ts.map +0 -1
- package/build/src/types/drive.js +0 -1
- package/build/src/types/event.d.ts +0 -16
- package/build/src/types/event.d.ts.map +0 -1
- package/build/src/types/index.d.ts +0 -15
- package/build/src/types/index.d.ts.map +0 -1
- package/build/src/types/index.js +0 -14
- package/build/src/types/input.d.ts +0 -35
- package/build/src/types/input.d.ts.map +0 -1
- package/build/src/types/input.js +0 -7
- package/build/src/types/lock.d.ts +0 -14
- package/build/src/types/lock.d.ts.map +0 -1
- package/build/src/types/lock.js +0 -7
- package/build/src/types/metadata.d.ts +0 -24
- package/build/src/types/metadata.d.ts.map +0 -1
- package/build/src/types/metadata.js +0 -7
- package/build/src/types/mixin.d.ts +0 -17
- package/build/src/types/mixin.d.ts.map +0 -1
- package/build/src/types/mixin.js +0 -7
- package/build/src/types/regenerate.d.ts +0 -12
- package/build/src/types/regenerate.d.ts.map +0 -1
- package/build/src/types/regenerate.js +0 -7
- package/build/src/types/service.d.ts +0 -25
- package/build/src/types/service.d.ts.map +0 -1
- package/build/src/types/service.js +0 -7
- package/build/src/utils/default_values.d.ts +0 -20
- package/build/src/utils/default_values.d.ts.map +0 -1
- package/build/src/utils/default_values.js +0 -19
- package/build/src/utils/helpers.d.ts +0 -19
- package/build/src/utils/helpers.d.ts.map +0 -1
- package/build/src/utils/helpers.js +0 -131
- package/build/src/utils/hooks.d.ts +0 -12
- package/build/src/utils/hooks.d.ts.map +0 -1
- package/build/src/utils/hooks.js +0 -42
- package/build/src/utils/symbols.d.ts +0 -8
- package/build/src/utils/symbols.d.ts.map +0 -1
- package/build/src/utils/symbols.js +0 -7
- package/build/stubs/config.stub +0 -140
- package/build/stubs/make/converter/main.stub +0 -20
- package/build/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import app from '@adonisjs/core/services/app';
|
|
8
|
+
import { isAttachmentDraft } from '../../core/attachment.js';
|
|
9
|
+
import { isAttachmentPending, markAttachmentPersisted } from '../../core/attachment_state.js';
|
|
10
|
+
const columnOptions = new WeakMap();
|
|
11
|
+
const saveStates = new WeakMap();
|
|
12
|
+
const deleteStates = new WeakMap();
|
|
13
|
+
const patchedModels = new WeakSet();
|
|
14
|
+
/**
|
|
15
|
+
* Persists one Attachment JSON value in a Lucid column and coordinates file cleanup.
|
|
16
|
+
*/
|
|
17
|
+
export function attachment(options = {}) {
|
|
18
|
+
return (target, propertyKey) => {
|
|
19
|
+
const Model = target.constructor;
|
|
20
|
+
const name = String(propertyKey);
|
|
21
|
+
Model.boot();
|
|
22
|
+
const columns = columnOptions.get(Model) ?? new Map();
|
|
23
|
+
columns.set(name, options);
|
|
24
|
+
columnOptions.set(Model, columns);
|
|
25
|
+
Model.$addColumn(name, makeColumnOptions(options));
|
|
26
|
+
if (!patchedModels.has(Model)) {
|
|
27
|
+
patchedModels.add(Model);
|
|
28
|
+
Model.before('save', prepareSave);
|
|
29
|
+
Model.after('save', finalizeSave);
|
|
30
|
+
Model.before('delete', prepareDelete);
|
|
31
|
+
Model.after('delete', finalizeDelete);
|
|
32
|
+
wrapSave(Model);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function makeColumnOptions(options) {
|
|
37
|
+
return {
|
|
38
|
+
prepare(value) {
|
|
39
|
+
return value ? JSON.stringify(value) : null;
|
|
40
|
+
},
|
|
41
|
+
consume(value) {
|
|
42
|
+
if (!value || typeof value !== 'string') {
|
|
43
|
+
return value ?? null;
|
|
44
|
+
}
|
|
45
|
+
return JSON.parse(value);
|
|
46
|
+
},
|
|
47
|
+
serialize: options.serialize ?? ((value) => value ?? null),
|
|
48
|
+
...(options.serializeAs !== undefined ? { serializeAs: options.serializeAs } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function prepareSave(row) {
|
|
52
|
+
const state = { attached: [], detached: [] };
|
|
53
|
+
for (const name of getColumnNames(row)) {
|
|
54
|
+
const previous = toAttachment(row.$original[name]);
|
|
55
|
+
const current = await persistDraft(row, name);
|
|
56
|
+
if (previous?.id === current?.id) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (current && isAttachmentPending(current)) {
|
|
60
|
+
state.attached.push(current);
|
|
61
|
+
}
|
|
62
|
+
if (previous) {
|
|
63
|
+
state.detached.push(previous);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
saveStates.set(row, state);
|
|
67
|
+
}
|
|
68
|
+
async function finalizeSave(row) {
|
|
69
|
+
const state = saveStates.get(row);
|
|
70
|
+
if (!state) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const commit = async () => {
|
|
74
|
+
markPersisted(state.attached);
|
|
75
|
+
await removeAll(state.detached);
|
|
76
|
+
};
|
|
77
|
+
const rollback = async () => {
|
|
78
|
+
await removeAll(state.attached);
|
|
79
|
+
};
|
|
80
|
+
if (row.$trx) {
|
|
81
|
+
row.$trx.after('commit', commit);
|
|
82
|
+
row.$trx.after('rollback', rollback);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
await commit();
|
|
86
|
+
}
|
|
87
|
+
saveStates.delete(row);
|
|
88
|
+
}
|
|
89
|
+
async function prepareDelete(row) {
|
|
90
|
+
deleteStates.set(row, Array.from(getColumnNames(row))
|
|
91
|
+
.map((name) => toAttachment(row.$attributes[name]))
|
|
92
|
+
.filter((value) => value !== null));
|
|
93
|
+
}
|
|
94
|
+
async function finalizeDelete(row) {
|
|
95
|
+
const attachments = deleteStates.get(row) ?? [];
|
|
96
|
+
const commit = () => removeAll(attachments);
|
|
97
|
+
if (row.$trx) {
|
|
98
|
+
row.$trx.after('commit', commit);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
await commit();
|
|
102
|
+
}
|
|
103
|
+
deleteStates.delete(row);
|
|
104
|
+
}
|
|
105
|
+
function wrapSave(Model) {
|
|
106
|
+
const save = Model.prototype.save;
|
|
107
|
+
Model.prototype.save = async function saveWithAttachmentCleanup() {
|
|
108
|
+
try {
|
|
109
|
+
return await save.call(this);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const state = saveStates.get(this);
|
|
113
|
+
saveStates.delete(this);
|
|
114
|
+
await removeAll(state?.attached ?? []);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function getColumnNames(row) {
|
|
120
|
+
return new Set(columnOptions.get(row.constructor)?.keys());
|
|
121
|
+
}
|
|
122
|
+
async function persistDraft(row, name) {
|
|
123
|
+
const value = row.$attributes[name];
|
|
124
|
+
if (!isAttachmentDraft(value)) {
|
|
125
|
+
return toAttachment(value);
|
|
126
|
+
}
|
|
127
|
+
const options = columnOptions.get(row.constructor)?.get(name);
|
|
128
|
+
const attachment = await value.persist({
|
|
129
|
+
...(options ? { options } : {}),
|
|
130
|
+
context: { model: row, field: name },
|
|
131
|
+
});
|
|
132
|
+
row.$attributes[name] = attachment;
|
|
133
|
+
return attachment;
|
|
134
|
+
}
|
|
135
|
+
function toAttachment(value) {
|
|
136
|
+
if (!value || typeof value !== 'object' || !('id' in value) || !('disk' in value) || !('path' in value)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
function markPersisted(attachments) {
|
|
142
|
+
attachments.forEach((attachment) => markAttachmentPersisted(attachment));
|
|
143
|
+
}
|
|
144
|
+
async function removeAll(attachments) {
|
|
145
|
+
if (attachments.length === 0) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const service = (await app.container.make('jrmc.attachment'));
|
|
149
|
+
await Promise.allSettled(attachments.map((attachment) => service.remove(attachment)));
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=attachment_column.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_column.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_column.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,6BAA6B,CAAA;AAG7C,OAAO,EAAE,iBAAiB,EAAmB,MAAM,0BAA0B,CAAA;AAC7E,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AA0B7F,MAAM,aAAa,GAAG,IAAI,OAAO,EAAoD,CAAA;AACrF,MAAM,UAAU,GAAG,IAAI,OAAO,EAA+B,CAAA;AAC7D,MAAM,YAAY,GAAG,IAAI,OAAO,EAAwB,CAAA;AACxD,MAAM,aAAa,GAAG,IAAI,OAAO,EAAU,CAAA;AAE3C;;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license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import { BaseModel } from '@adonisjs/lucid/orm';
|
|
8
|
+
import type { DateTime } from 'luxon';
|
|
9
|
+
import type { Attachment } from '../../core/attachment.js';
|
|
10
|
+
/**
|
|
11
|
+
* Default Lucid model for the polymorphic attachments table.
|
|
12
|
+
* Applications may extend this model to add their own scopes and serialization rules.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AttachmentModel extends BaseModel {
|
|
15
|
+
static table: string;
|
|
16
|
+
static selfAssignPrimaryKey: boolean;
|
|
17
|
+
id: string;
|
|
18
|
+
attachableType: string;
|
|
19
|
+
attachableId: string;
|
|
20
|
+
field: string;
|
|
21
|
+
ownerKey: string | null;
|
|
22
|
+
position: number | null;
|
|
23
|
+
parentId: string | null;
|
|
24
|
+
variantKey: string | null;
|
|
25
|
+
disk: string;
|
|
26
|
+
path: string;
|
|
27
|
+
name: string;
|
|
28
|
+
originalName: string;
|
|
29
|
+
mimeType: string;
|
|
30
|
+
extname: string;
|
|
31
|
+
size: number;
|
|
32
|
+
metadata: Record<string, unknown> | null;
|
|
33
|
+
createdAt: DateTime;
|
|
34
|
+
updatedAt: DateTime;
|
|
35
|
+
toAttachment(): Attachment;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=attachment_model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_model.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAU,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,MAAM,CAAC,KAAK,SAAgB;IAC5B,MAAM,CAAC,oBAAoB,UAAO;IAG1B,EAAE,EAAE,MAAM,CAAA;IAGV,cAAc,EAAE,MAAM,CAAA;IAGtB,YAAY,EAAE,MAAM,CAAA;IAGpB,KAAK,EAAE,MAAM,CAAA;IAGb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAGvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAGvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAGvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IAGzB,IAAI,EAAE,MAAM,CAAA;IAGZ,IAAI,EAAE,MAAM,CAAA;IAGZ,IAAI,EAAE,MAAM,CAAA;IAGZ,YAAY,EAAE,MAAM,CAAA;IAGpB,QAAQ,EAAE,MAAM,CAAA;IAGhB,OAAO,EAAE,MAAM,CAAA;IAGf,IAAI,EAAE,MAAM,CAAA;IAcZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAGxC,SAAS,EAAE,QAAQ,CAAA;IAGnB,SAAS,EAAE,QAAQ,CAAA;IAE3B,YAAY,IAAI,UAAU;CAa3B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
8
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
10
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
};
|
|
13
|
+
import { BaseModel, column } from '@adonisjs/lucid/orm';
|
|
14
|
+
/**
|
|
15
|
+
* Default Lucid model for the polymorphic attachments table.
|
|
16
|
+
* Applications may extend this model to add their own scopes and serialization rules.
|
|
17
|
+
*/
|
|
18
|
+
export class AttachmentModel extends BaseModel {
|
|
19
|
+
static table = 'attachments';
|
|
20
|
+
static selfAssignPrimaryKey = true;
|
|
21
|
+
toAttachment() {
|
|
22
|
+
return {
|
|
23
|
+
id: this.id,
|
|
24
|
+
disk: this.disk,
|
|
25
|
+
path: this.path,
|
|
26
|
+
name: this.name,
|
|
27
|
+
originalName: this.originalName,
|
|
28
|
+
mimeType: this.mimeType,
|
|
29
|
+
extname: this.extname,
|
|
30
|
+
size: this.size,
|
|
31
|
+
...(this.metadata ? { metadata: this.metadata } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
__decorate([
|
|
36
|
+
column({ isPrimary: true })
|
|
37
|
+
], AttachmentModel.prototype, "id", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
column()
|
|
40
|
+
], AttachmentModel.prototype, "attachableType", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
column()
|
|
43
|
+
], AttachmentModel.prototype, "attachableId", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
column()
|
|
46
|
+
], AttachmentModel.prototype, "field", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
column({ serializeAs: null })
|
|
49
|
+
], AttachmentModel.prototype, "ownerKey", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
column()
|
|
52
|
+
], AttachmentModel.prototype, "position", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
column()
|
|
55
|
+
], AttachmentModel.prototype, "parentId", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
column()
|
|
58
|
+
], AttachmentModel.prototype, "variantKey", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
column()
|
|
61
|
+
], AttachmentModel.prototype, "disk", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
column()
|
|
64
|
+
], AttachmentModel.prototype, "path", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
column()
|
|
67
|
+
], AttachmentModel.prototype, "name", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
column()
|
|
70
|
+
], AttachmentModel.prototype, "originalName", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
column()
|
|
73
|
+
], AttachmentModel.prototype, "mimeType", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
column()
|
|
76
|
+
], AttachmentModel.prototype, "extname", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
column()
|
|
79
|
+
], AttachmentModel.prototype, "size", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
column({
|
|
82
|
+
prepare(value) {
|
|
83
|
+
return value === null ? null : JSON.stringify(value);
|
|
84
|
+
},
|
|
85
|
+
consume(value) {
|
|
86
|
+
if (value === null || value === undefined || typeof value !== 'string') {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
return JSON.parse(value);
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
], AttachmentModel.prototype, "metadata", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
column.dateTime({ autoCreate: true })
|
|
95
|
+
], AttachmentModel.prototype, "createdAt", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
98
|
+
], AttachmentModel.prototype, "updatedAt", void 0);
|
|
99
|
+
//# sourceMappingURL=attachment_model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_model.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;;;;;;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAKvD;;;GAGG;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,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACtD,CAAC;QACD,OAAO,CAAC,KAAc;YACpB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACvE,OAAO,KAAuC,CAAA;YAChD,CAAC;YAED,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAA4B,CAAA;QACrD,CAAC;KACF,CAAC;iDAC8C;AAGxC;IADP,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;kDACX;AAGnB;IADP,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;kDAC7B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
export type AttachmentOwner<Model = unknown> = {
|
|
8
|
+
type: string;
|
|
9
|
+
id: string;
|
|
10
|
+
field: string;
|
|
11
|
+
model?: Model;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Produces the database key that enforces one original attachment per owner field.
|
|
15
|
+
* A digest keeps the indexed column bounded for arbitrary polymorphic identifiers.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createAttachmentOwnerKey(owner: AttachmentOwner): string;
|
|
18
|
+
//# sourceMappingURL=attachment_owner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_owner.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_owner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,OAAO,IAAI;IAC7C,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAEvE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
/**
|
|
9
|
+
* Produces the database key that enforces one original attachment per owner field.
|
|
10
|
+
* A digest keeps the indexed column bounded for arbitrary polymorphic identifiers.
|
|
11
|
+
*/
|
|
12
|
+
export function createAttachmentOwnerKey(owner) {
|
|
13
|
+
return createHash('sha256').update(JSON.stringify([owner.type, owner.id, owner.field])).digest('hex');
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=attachment_owner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_owner.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_owner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AASxC;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAsB;IAC7D,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACvG,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import type { LucidRow } from "@adonisjs/lucid/types/model";
|
|
8
|
+
import type { AttachmentDraft, CreateAttachmentInput } from "../../core/attachment.js";
|
|
9
|
+
import type { AttachmentPersistenceOptions } from "../../core/attachment_options.js";
|
|
10
|
+
import { AttachmentModel } from "./attachment_model.js";
|
|
11
|
+
type AttachmentRelationInput = CreateAttachmentInput | AttachmentDraft;
|
|
12
|
+
type AttachmentRelationRow = LucidRow & {
|
|
13
|
+
$isPersisted: boolean;
|
|
14
|
+
$primaryKeyValue: string | number | null | undefined;
|
|
15
|
+
constructor: {
|
|
16
|
+
table?: string;
|
|
17
|
+
name: string;
|
|
18
|
+
boot(): void;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type RelationKind = "one" | "many";
|
|
22
|
+
type RelationDefinition = {
|
|
23
|
+
kind: RelationKind;
|
|
24
|
+
field: string;
|
|
25
|
+
options: AttachmentRelationOptions<any>;
|
|
26
|
+
};
|
|
27
|
+
export type AttachmentRelationOptions<Model = any> = AttachmentPersistenceOptions<Model> & {
|
|
28
|
+
type?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Declares one attachment persisted in the polymorphic attachments table.
|
|
32
|
+
*/
|
|
33
|
+
export declare function attachmentRelation<Model = LucidRow>(options?: AttachmentRelationOptions<Model>): PropertyDecorator;
|
|
34
|
+
/**
|
|
35
|
+
* Declares an ordered attachment collection persisted in the polymorphic attachments table.
|
|
36
|
+
*/
|
|
37
|
+
export declare function attachmentsRelation<Model = LucidRow>(options?: AttachmentRelationOptions<Model>): PropertyDecorator;
|
|
38
|
+
export declare class AttachmentRelation {
|
|
39
|
+
#private;
|
|
40
|
+
constructor(row: AttachmentRelationRow, definition: RelationDefinition);
|
|
41
|
+
get(): Promise<AttachmentModel | null>;
|
|
42
|
+
attach(input: AttachmentRelationInput): Promise<AttachmentModel>;
|
|
43
|
+
set(input: AttachmentRelationInput): Promise<AttachmentModel>;
|
|
44
|
+
replace(input: AttachmentRelationInput): Promise<AttachmentModel>;
|
|
45
|
+
detach(): Promise<void>;
|
|
46
|
+
variants(): Promise<AttachmentModel[]>;
|
|
47
|
+
regenerateVariants(variantKeys?: readonly string[]): Promise<boolean>;
|
|
48
|
+
}
|
|
49
|
+
export declare class AttachmentCollectionRelation {
|
|
50
|
+
#private;
|
|
51
|
+
constructor(row: AttachmentRelationRow, definition: RelationDefinition);
|
|
52
|
+
all(): Promise<AttachmentModel[]>;
|
|
53
|
+
add(input: AttachmentRelationInput, position?: number): Promise<AttachmentModel>;
|
|
54
|
+
remove(id: string): Promise<boolean>;
|
|
55
|
+
clear(): Promise<void>;
|
|
56
|
+
replaceAll(inputs: readonly AttachmentRelationInput[]): Promise<AttachmentModel[]>;
|
|
57
|
+
move(id: string, position: number): Promise<AttachmentModel[]>;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=attachment_relation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_relation.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_relation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,KAAK,EAEV,eAAe,EACf,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAGrF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,KAAK,uBAAuB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AAEvE,KAAK,qBAAqB,GAAG,QAAQ,GAAG;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,WAAW,EAAE;QAAE,KAAK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AED,qBAAa,4BAA4B;;gBAI3B,GAAG,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB;IAKhE,GAAG,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAKjC,GAAG,CACP,KAAK,EAAE,uBAAuB,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,CAAC;IAUrB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,UAAU,CACd,MAAM,EAAE,SAAS,uBAAuB,EAAE,GACzC,OAAO,CAAC,eAAe,EAAE,CAAC;IASvB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAkBrE"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import app from "@adonisjs/core/services/app";
|
|
8
|
+
import { AttachmentModel } from "./attachment_model.js";
|
|
9
|
+
import { LucidAttachmentLifecycleService } from "./lucid_attachment_lifecycle_service.js";
|
|
10
|
+
import { LucidAttachmentStore } from "./lucid_attachment_store.js";
|
|
11
|
+
const relationDefinitions = new WeakMap();
|
|
12
|
+
const relationInstances = new WeakMap();
|
|
13
|
+
/**
|
|
14
|
+
* Declares one attachment persisted in the polymorphic attachments table.
|
|
15
|
+
*/
|
|
16
|
+
export function attachmentRelation(options = {}) {
|
|
17
|
+
return defineRelation("one", options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Declares an ordered attachment collection persisted in the polymorphic attachments table.
|
|
21
|
+
*/
|
|
22
|
+
export function attachmentsRelation(options = {}) {
|
|
23
|
+
return defineRelation("many", options);
|
|
24
|
+
}
|
|
25
|
+
export class AttachmentRelation {
|
|
26
|
+
#row;
|
|
27
|
+
#definition;
|
|
28
|
+
constructor(row, definition) {
|
|
29
|
+
this.#row = row;
|
|
30
|
+
this.#definition = definition;
|
|
31
|
+
}
|
|
32
|
+
async get() {
|
|
33
|
+
const lifecycle = await this.#lifecycle();
|
|
34
|
+
return lifecycle.get(this.#owner());
|
|
35
|
+
}
|
|
36
|
+
async attach(input) {
|
|
37
|
+
const owner = this.#owner();
|
|
38
|
+
const lifecycle = await this.#lifecycle();
|
|
39
|
+
if (await lifecycle.get(owner)) {
|
|
40
|
+
throw new Error(`Attachment relation "${owner.field}" already has an attachment; use replace() or set()`);
|
|
41
|
+
}
|
|
42
|
+
return lifecycle.attach(owner, input, this.#definition.options);
|
|
43
|
+
}
|
|
44
|
+
set(input) {
|
|
45
|
+
return this.replace(input);
|
|
46
|
+
}
|
|
47
|
+
async replace(input) {
|
|
48
|
+
const lifecycle = await this.#lifecycle();
|
|
49
|
+
return lifecycle.replace(this.#owner(), input, this.#definition.options);
|
|
50
|
+
}
|
|
51
|
+
async detach() {
|
|
52
|
+
const lifecycle = await this.#lifecycle();
|
|
53
|
+
await lifecycle.detach(this.#owner());
|
|
54
|
+
}
|
|
55
|
+
async variants() {
|
|
56
|
+
const lifecycle = await this.#lifecycle();
|
|
57
|
+
return lifecycle.listVariants(this.#owner());
|
|
58
|
+
}
|
|
59
|
+
async regenerateVariants(variantKeys) {
|
|
60
|
+
const attachment = await this.get();
|
|
61
|
+
if (!attachment) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const service = await resolveAttachmentService();
|
|
65
|
+
await service.scheduleVariantGeneration(attachment.toAttachment(), variantKeys);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
async #lifecycle() {
|
|
69
|
+
return new LucidAttachmentLifecycleService(await resolveAttachmentService(), new LucidAttachmentStore(AttachmentModel, this.#row.$trx ? { client: this.#row.$trx } : {}));
|
|
70
|
+
}
|
|
71
|
+
#owner() {
|
|
72
|
+
return createOwner(this.#row, this.#definition);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class AttachmentCollectionRelation {
|
|
76
|
+
#row;
|
|
77
|
+
#definition;
|
|
78
|
+
constructor(row, definition) {
|
|
79
|
+
this.#row = row;
|
|
80
|
+
this.#definition = definition;
|
|
81
|
+
}
|
|
82
|
+
async all() {
|
|
83
|
+
const lifecycle = await this.#lifecycle();
|
|
84
|
+
return lifecycle.listCollection(this.#owner());
|
|
85
|
+
}
|
|
86
|
+
async add(input, position) {
|
|
87
|
+
const lifecycle = await this.#lifecycle();
|
|
88
|
+
return lifecycle.add(this.#owner(), input, position, this.#definition.options);
|
|
89
|
+
}
|
|
90
|
+
async remove(id) {
|
|
91
|
+
const lifecycle = await this.#lifecycle();
|
|
92
|
+
return lifecycle.removeCollectionItem(this.#owner(), id);
|
|
93
|
+
}
|
|
94
|
+
async clear() {
|
|
95
|
+
const lifecycle = await this.#lifecycle();
|
|
96
|
+
await lifecycle.clearCollection(this.#owner());
|
|
97
|
+
}
|
|
98
|
+
async replaceAll(inputs) {
|
|
99
|
+
const lifecycle = await this.#lifecycle();
|
|
100
|
+
return lifecycle.replaceCollection(this.#owner(), inputs, this.#definition.options);
|
|
101
|
+
}
|
|
102
|
+
async move(id, position) {
|
|
103
|
+
const lifecycle = await this.#lifecycle();
|
|
104
|
+
return lifecycle.moveCollectionItem(this.#owner(), id, position);
|
|
105
|
+
}
|
|
106
|
+
async #lifecycle() {
|
|
107
|
+
return new LucidAttachmentLifecycleService(await resolveAttachmentService(), new LucidAttachmentStore(AttachmentModel, this.#row.$trx ? { client: this.#row.$trx } : {}));
|
|
108
|
+
}
|
|
109
|
+
#owner() {
|
|
110
|
+
return createOwner(this.#row, this.#definition);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function defineRelation(kind, options) {
|
|
114
|
+
return (target, propertyKey) => {
|
|
115
|
+
const Model = target.constructor;
|
|
116
|
+
const field = String(propertyKey);
|
|
117
|
+
const definitions = relationDefinitions.get(Model) ?? new Map();
|
|
118
|
+
if (definitions.has(field)) {
|
|
119
|
+
throw new Error(`Attachment relation "${field}" is already declared on this model`);
|
|
120
|
+
}
|
|
121
|
+
Model.boot();
|
|
122
|
+
definitions.set(field, { kind, field, options });
|
|
123
|
+
relationDefinitions.set(Model, definitions);
|
|
124
|
+
Object.defineProperty(target, propertyKey, {
|
|
125
|
+
configurable: true,
|
|
126
|
+
enumerable: false,
|
|
127
|
+
get() {
|
|
128
|
+
const instances = relationInstances.get(this) ?? new Map();
|
|
129
|
+
const existing = instances.get(field);
|
|
130
|
+
if (existing) {
|
|
131
|
+
return existing;
|
|
132
|
+
}
|
|
133
|
+
const relation = kind === "one"
|
|
134
|
+
? new AttachmentRelation(this, definitions.get(field))
|
|
135
|
+
: new AttachmentCollectionRelation(this, definitions.get(field));
|
|
136
|
+
instances.set(field, relation);
|
|
137
|
+
relationInstances.set(this, instances);
|
|
138
|
+
return relation;
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function createOwner(row, definition) {
|
|
144
|
+
if (!row.$isPersisted ||
|
|
145
|
+
row.$primaryKeyValue === null ||
|
|
146
|
+
row.$primaryKeyValue === undefined) {
|
|
147
|
+
throw new Error("Attachment relations require a persisted Lucid model");
|
|
148
|
+
}
|
|
149
|
+
const type = definition.options.type ?? row.constructor.table;
|
|
150
|
+
if (!type) {
|
|
151
|
+
throw new Error("Attachment relations require a Lucid model table or an explicit relation type");
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
type,
|
|
155
|
+
id: String(row.$primaryKeyValue),
|
|
156
|
+
field: definition.field,
|
|
157
|
+
model: row,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async function resolveAttachmentService() {
|
|
161
|
+
return (await app.container.make("jrmc.attachment"));
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=attachment_relation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_relation.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachment_relation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,6BAA6B,CAAC;AAW9C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAuBnE,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAGpC,CAAC;AACJ,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAGlC,CAAC;AAEJ;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAA4C,EAAE;IAE9C,OAAO,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAA4C,EAAE;IAE9C,OAAO,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,OAAO,kBAAkB;IACpB,IAAI,CAAwB;IAC5B,WAAW,CAAqB;IAEzC,YAAY,GAA0B,EAAE,UAA8B;QACpE,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAC1C,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAA8B;QACzC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAE1C,IAAI,MAAM,SAAS,CA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GAAG,CAAC,gBAAgB,KAAK,IAAI;QAC7B,GAAG,CAAC,gBAAgB,KAAK,SAAS,EAClC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;IAE9D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI;QACJ,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC;QAChC,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,KAAK,EAAE,GAAG;KACX,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,wBAAwB;IACrC,OAAO,CAAC,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAsB,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
export type AttachmentsTableStubOptions = {
|
|
8
|
+
directory: string;
|
|
9
|
+
tableName?: string;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
};
|
|
12
|
+
export type AttachmentsTableStubState = {
|
|
13
|
+
destination: string;
|
|
14
|
+
tableName: string;
|
|
15
|
+
className: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Builds the state consumed by the attachments-table migration stub.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createAttachmentsTableStubState(options: AttachmentsTableStubOptions): AttachmentsTableStubState;
|
|
21
|
+
//# sourceMappingURL=attachments_table_stub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments_table_stub.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachments_table_stub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,2BAA2B,GACnC,yBAAyB,CAc3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
/**
|
|
9
|
+
* Builds the state consumed by the attachments-table migration stub.
|
|
10
|
+
*/
|
|
11
|
+
export function createAttachmentsTableStubState(options) {
|
|
12
|
+
const tableName = options.tableName ?? 'attachments';
|
|
13
|
+
if (!/^[a-z][a-z0-9_]*$/.test(tableName)) {
|
|
14
|
+
throw new Error('Lucid attachment table names must be snake_case identifiers');
|
|
15
|
+
}
|
|
16
|
+
const timestamp = options.timestamp ?? Date.now();
|
|
17
|
+
return {
|
|
18
|
+
destination: join(options.directory, `${timestamp}_create_${tableName}_table.ts`),
|
|
19
|
+
tableName,
|
|
20
|
+
className: toPascalCase(tableName),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function toPascalCase(value) {
|
|
24
|
+
return value.replace(/(^|_)([a-z0-9])/g, (_, _separator, character) => character.toUpperCase());
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=attachments_table_stub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments_table_stub.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/attachments_table_stub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAchC;;GAEG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAoC;IAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,aAAa,CAAA;IAEpD,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;IAChF,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;IAEjD,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,SAAS,WAAW,SAAS,WAAW,CAAC;QACjF,SAAS;QACT,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC;KACnC,CAAA;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,UAAkB,EAAE,SAAiB,EAAE,EAAE,CACpF,SAAS,CAAC,WAAW,EAAE,CACxB,CAAA;AACH,CAAC"}
|