@holo-js/media 0.3.12 → 0.3.14
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/dist/index.d.ts +1 -0
- package/dist/index.mjs +32 -4
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -317,6 +317,7 @@ type MediaEnabledResult<TValue, TCollectionName extends string, TConversionName
|
|
|
317
317
|
type MediaModelStatic = {
|
|
318
318
|
readonly definition: {
|
|
319
319
|
readonly name: string;
|
|
320
|
+
readonly softDeletes: boolean;
|
|
320
321
|
readonly table: TableDefinition;
|
|
321
322
|
};
|
|
322
323
|
readonly resolveRelationUsing: (name: string, resolver: DynamicRelationResolver) => unknown;
|
package/dist/index.mjs
CHANGED
|
@@ -1509,6 +1509,16 @@ var MediaAdder = class _MediaAdder {
|
|
|
1509
1509
|
};
|
|
1510
1510
|
|
|
1511
1511
|
// src/model/entity.ts
|
|
1512
|
+
async function clearEntityMedia(entity, collectionName) {
|
|
1513
|
+
const query = createQuery(entity, collectionName);
|
|
1514
|
+
if (!query) {
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
const rows = await query.get();
|
|
1518
|
+
for (const row of rows) {
|
|
1519
|
+
await new MediaItem(row, entity).delete();
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1512
1522
|
function getOwnerKey(entity) {
|
|
1513
1523
|
const ownerDefinition = entity.getRepository().definition;
|
|
1514
1524
|
const ownerId = entity.get(ownerDefinition.primaryKey);
|
|
@@ -1591,10 +1601,7 @@ function installEntityMediaMethods() {
|
|
|
1591
1601
|
return query.exists();
|
|
1592
1602
|
};
|
|
1593
1603
|
prototype.clearMediaCollection = async function clearMediaCollection(collectionName) {
|
|
1594
|
-
|
|
1595
|
-
for (const item of items) {
|
|
1596
|
-
await item.delete();
|
|
1597
|
-
}
|
|
1604
|
+
await clearEntityMedia(this, collectionName);
|
|
1598
1605
|
};
|
|
1599
1606
|
prototype.regenerateMedia = async function regenerateMedia(collectionName, conversions) {
|
|
1600
1607
|
const items = await this.getMedia(collectionName);
|
|
@@ -1810,6 +1817,26 @@ function normalizeMediaDefinition(input) {
|
|
|
1810
1817
|
});
|
|
1811
1818
|
}
|
|
1812
1819
|
|
|
1820
|
+
// src/model/observer.ts
|
|
1821
|
+
var modelObserverRegistrar = /* @__PURE__ */ Symbol.for("holo-js.db.model-observer-registrar");
|
|
1822
|
+
var deletingObserver = Object.freeze({
|
|
1823
|
+
deleting(entity) {
|
|
1824
|
+
return clearEntityMedia(entity);
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
var forceDeletingObserver = Object.freeze({
|
|
1828
|
+
forceDeleting(entity) {
|
|
1829
|
+
return clearEntityMedia(entity);
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
function observeMediaModelDeletion(model) {
|
|
1833
|
+
const registerObserver = model[modelObserverRegistrar];
|
|
1834
|
+
if (!registerObserver) {
|
|
1835
|
+
throw new Error("[Holo Media] The database model does not support internal observer registration.");
|
|
1836
|
+
}
|
|
1837
|
+
registerObserver(model.definition.softDeletes ? forceDeletingObserver : deletingObserver);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1813
1840
|
// src/defineMediaModel.ts
|
|
1814
1841
|
function defineMediaModel(model, definition) {
|
|
1815
1842
|
installEntityMediaMethods();
|
|
@@ -1817,6 +1844,7 @@ function defineMediaModel(model, definition) {
|
|
|
1817
1844
|
resolveMediaDefinition(definition)
|
|
1818
1845
|
);
|
|
1819
1846
|
registerMediaDefinition(model, resolvedDefinition);
|
|
1847
|
+
observeMediaModelDeletion(model);
|
|
1820
1848
|
model.resolveRelationUsing("media", () => morphMany(
|
|
1821
1849
|
() => Media,
|
|
1822
1850
|
"model"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/media",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "Holo-JS Framework - media collections and conversions for Holo-JS models",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"test": "vitest --run"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@holo-js/config": "^0.3.
|
|
32
|
-
"@holo-js/db": "^0.3.
|
|
33
|
-
"@holo-js/queue": "^0.3.
|
|
34
|
-
"@holo-js/storage": "^0.3.
|
|
31
|
+
"@holo-js/config": "^0.3.14",
|
|
32
|
+
"@holo-js/db": "^0.3.14",
|
|
33
|
+
"@holo-js/queue": "^0.3.14",
|
|
34
|
+
"@holo-js/storage": "^0.3.14",
|
|
35
35
|
"sharp": "^0.34.4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@holo-js/db-sqlite": "^0.3.
|
|
38
|
+
"@holo-js/db-sqlite": "^0.3.14",
|
|
39
39
|
"tsup": "^8.3.5",
|
|
40
40
|
"typescript": "^5.7.2",
|
|
41
41
|
"vitest": "^4.1.5"
|