Skip to content

Add provenance metadata field to the asset class & store metadata #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class Asset {
public dataFormat?: DataFormat;
public dependencies: Asset[];
public clean?: boolean;
public provenance?: AssetId;

/**
* Construct an Asset.
Expand Down Expand Up @@ -46,6 +47,10 @@ export default class Asset {
this.dependencies = [];
}

setProvenance(id: AssetId | undefined) {
this.provenance = id;
}

setData (data: AssetData | undefined, dataFormat: DataFormat | undefined, generateId?: boolean) {
if (data && !dataFormat) {
throw new Error('Data provided without specifying its format');
Expand Down
12 changes: 10 additions & 2 deletions src/ScratchStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ interface HelperWithPriority {
priority: number
}

export interface StoreMetadata {
/**
* The assetId of the asset that the currently uploaded one is based on.
*/
provenance?: AssetId;
}

export class ScratchStorage {
public defaultAssetId: Record<AssetType['name'], AssetId>;
public builtinHelper: BuiltinHelper;
Expand Down Expand Up @@ -246,10 +253,11 @@ export class ScratchStorage {
* @param {AssetType} assetType - The type of asset to fetch. This also determines which asset store to use.
* @param {?DataFormat} [dataFormat] - Optional: load this format instead of the AssetType's default.
* @param {Buffer} data - Data to store for the asset
* @param {?string} [assetId] - The ID of the asset to fetch: a project ID, MD5, etc.
* @param {?string} [assetId] - The ID of the asset to store: a project ID, MD5, etc.
* @param {?object} [_storeMetadata] - Optional: metadata for the save operation
* @return {Promise.<object>} A promise for asset metadata
*/
store (assetType: AssetType, dataFormat: DataFormat | null | undefined, data: AssetData, assetId?: AssetId) {
store (assetType: AssetType, dataFormat: DataFormat | null | undefined, data: AssetData, assetId?: AssetId, _storeMetadata?: StoreMetadata) {
dataFormat = dataFormat || assetType.runtimeFormat;

return this.webHelper.store(assetType, dataFormat, data, assetId)
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ScratchStorage} from './ScratchStorage';
import {ScratchStorage, StoreMetadata} from './ScratchStorage';
import Asset, {AssetId} from './Asset';
import {AssetType} from './AssetType';
import {DataFormat} from './DataFormat';
Expand All @@ -15,5 +15,6 @@ export {
AssetId,
AssetType,
DataFormat,
Helper
Helper,
StoreMetadata
};