@seedprotocol/sdk 0.7.9 → 0.7.10-next.1344.g3828e8a
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 +1 -1
- package/dist/{BaseFileManager-BAlySv8w.js → BaseFileManager-DLou1TZS.js} +5 -1
- package/dist/BaseFileManager-DLou1TZS.js.map +1 -0
- package/dist/{Item-Bf4kWKpH.js → Item-CXLcIHsi.js} +559 -346
- package/dist/Item-CXLcIHsi.js.map +1 -0
- package/dist/{ModelProperty-BlaEgb_U.js → ModelProperty-B3mfR6u4.js} +35 -35
- package/dist/{ModelProperty-BlaEgb_U.js.map → ModelProperty-B3mfR6u4.js.map} +1 -1
- package/dist/{Schema-J_1f6p0c.js → Schema-BeUyEmte.js} +18 -18
- package/dist/{Schema-J_1f6p0c.js.map → Schema-BeUyEmte.js.map} +1 -1
- package/dist/{SchemaValidationService-CnmKyzR-.js → SchemaValidationService-C1xqJFxI.js} +5 -5
- package/dist/{SchemaValidationService-CnmKyzR-.js.map → SchemaValidationService-C1xqJFxI.js.map} +1 -1
- package/dist/{errors-C1qUEZ7A.js → browserSupport-C64rX-2I.js} +38 -2
- package/dist/browserSupport-C64rX-2I.js.map +1 -0
- package/dist/{configurePlatform-CiOJ1R3q.js → configurePlatform-WkmvqeTO.js} +2 -2
- package/dist/{configurePlatform-CiOJ1R3q.js.map → configurePlatform-WkmvqeTO.js.map} +1 -1
- package/dist/{detachRowsBeforeDelete-sEaUwlOU.js → detachRowsBeforeDelete-BZr_0iZU.js} +2 -2
- package/dist/{detachRowsBeforeDelete-sEaUwlOU.js.map → detachRowsBeforeDelete-BZr_0iZU.js.map} +1 -1
- package/dist/dist/{BaseFileManager-BAlySv8w.d.ts → BaseFileManager-DLou1TZS.d.ts} +3 -1
- package/dist/dist/BaseFileManager-DLou1TZS.d.ts.map +1 -0
- package/dist/dist/{configurePlatform-CiOJ1R3q.d.ts → configurePlatform-WkmvqeTO.d.ts} +1 -1
- package/dist/dist/configurePlatform-WkmvqeTO.d.ts.map +1 -0
- package/dist/dist/{index-D0V-mjCV.d.ts → index-BjWk0x4-.d.ts} +1 -1
- package/dist/dist/{index-D0V-mjCV.d.ts.map → index-BjWk0x4-.d.ts.map} +1 -1
- package/dist/dist/{index.node-CYPemH-t.d.ts → index.node-BfiBriEq.d.ts} +7 -1
- package/dist/dist/{index.node-CYPemH-t.d.ts.map → index.node-BfiBriEq.d.ts.map} +1 -1
- package/dist/dist/platform.node.d.ts +2 -2
- package/dist/{eas-wB_fQ8Tc.js → eas-DpHg66jR.js} +5 -5
- package/dist/{eas-wB_fQ8Tc.js.map → eas-DpHg66jR.js.map} +1 -1
- package/dist/{errors-DLSoqSHG.js → errors-DpC9W4i3.js} +84 -45
- package/dist/{errors-DLSoqSHG.js.map → errors-DpC9W4i3.js.map} +1 -1
- package/dist/{getPublishPayload-BnIwpwz1.js → getPublishPayload-yidQCgY_.js} +8 -8
- package/dist/{getPublishPayload-BnIwpwz1.js.map → getPublishPayload-yidQCgY_.js.map} +1 -1
- package/dist/{getPublishPendingDiff-D6_-A5ns.js → getPublishPendingDiff-D__9bh6d.js} +7 -7
- package/dist/{getPublishPendingDiff-D6_-A5ns.js.map → getPublishPendingDiff-D__9bh6d.js.map} +1 -1
- package/dist/{getPublishUploads-sS6JfPgz.js → getPublishUploads-BdZmYCo2.js} +7 -7
- package/dist/{getPublishUploads-sS6JfPgz.js.map → getPublishUploads-BdZmYCo2.js.map} +1 -1
- package/dist/{index-CYGWPoOx.js → index-BMHqJ4kN.js} +7 -7
- package/dist/index-BMHqJ4kN.js.map +1 -0
- package/dist/{index-D0V-mjCV.js → index-BjWk0x4-.js} +2 -2
- package/dist/index-BjWk0x4-.js.map +1 -0
- package/dist/{index-DmTtj1nk.js → index-CVYB2g7a.js} +402 -20
- package/dist/index-CVYB2g7a.js.map +1 -0
- package/dist/{index-BVBmz_cc.js → index-uDLe9y9H.js} +7 -7
- package/dist/index-uDLe9y9H.js.map +1 -0
- package/dist/{index.browser-CUmBVYen.js → index.browser-OACFlpMH.js} +46 -10
- package/dist/index.browser-OACFlpMH.js.map +1 -0
- package/dist/{index.node-CYPemH-t.js → index.node-BfiBriEq.js} +31 -4
- package/dist/index.node-BfiBriEq.js.map +1 -0
- package/dist/main.js +17 -16
- package/dist/main.js.map +1 -1
- package/dist/{modelPropertyRecordSchemas-C7UgA5TH.js → modelPropertyRecordSchemas-BGvtTyaG.js} +5 -5
- package/dist/{modelPropertyRecordSchemas-C7UgA5TH.js.map → modelPropertyRecordSchemas-BGvtTyaG.js.map} +1 -1
- package/dist/node.js +8 -8
- package/dist/platform.browser.js +6 -6
- package/dist/platform.node.js +4 -4
- package/dist/{property-BxUYznH0.js → property-QjljUeb9.js} +8 -8
- package/dist/{property-BxUYznH0.js.map → property-QjljUeb9.js.map} +1 -1
- package/dist/{publishGraph-EcB40Uii.js → publishGraph-CP8IROkb.js} +5 -5
- package/dist/{publishGraph-EcB40Uii.js.map → publishGraph-CP8IROkb.js.map} +1 -1
- package/dist/{readHtmlBodyForStorageSeed-D6KPtWoR.js → readHtmlBodyForStorageSeed-D3OPk2iU.js} +10 -10
- package/dist/{readHtmlBodyForStorageSeed-D6KPtWoR.js.map → readHtmlBodyForStorageSeed-D3OPk2iU.js.map} +1 -1
- package/dist/src/Item/Item.d.ts +26 -5
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +20 -5
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/loadProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/propertyWrite.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/archive/exportArchive.d.ts +57 -0
- package/dist/src/archive/exportArchive.d.ts.map +1 -0
- package/dist/src/browser/db/Db.d.ts +5 -0
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/browser/helpers/tolerantWebAccess.d.ts +12 -1
- package/dist/src/browser/helpers/tolerantWebAccess.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +14 -4
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/db/Db/BaseDb.d.ts +2 -0
- package/dist/src/db/Db/BaseDb.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/errors.d.ts +11 -0
- package/dist/src/helpers/FileManager/errors.d.ts.map +1 -1
- package/dist/src/helpers/browserSupport.d.ts +23 -0
- package/dist/src/helpers/browserSupport.d.ts.map +1 -0
- package/dist/src/helpers/cachedPropertyRefresh.d.ts +6 -6
- package/dist/src/helpers/cachedPropertyRefresh.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityCache.d.ts +34 -3
- package/dist/src/helpers/entity/entityCache.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityLifecycle.d.ts +21 -3
- package/dist/src/helpers/entity/entityLifecycle.d.ts.map +1 -1
- package/dist/src/helpers/propertyDefinition.d.ts +2 -0
- package/dist/src/helpers/propertyDefinition.d.ts.map +1 -1
- package/dist/src/helpers/tabCoordinator.d.ts +9 -2
- package/dist/src/helpers/tabCoordinator.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IDb.d.ts +6 -0
- package/dist/src/interfaces/IDb.d.ts.map +1 -1
- package/dist/src/node/db/Db.d.ts +6 -0
- package/dist/src/node/db/Db.d.ts.map +1 -1
- package/dist/src/outbox/conflicts.d.ts.map +1 -1
- package/dist/src/outbox/outbox.d.ts +6 -0
- package/dist/src/outbox/outbox.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +16 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/{syncDbWithEas-CA7PvBgu.js → syncDbWithEas-CDjSNrVR.js} +14 -14
- package/dist/{syncDbWithEas-CA7PvBgu.js.map → syncDbWithEas-CDjSNrVR.js.map} +1 -1
- package/dist/{tabEvents-CaVmngqr.js → tabEvents-BHPY5I08.js} +38 -12
- package/dist/tabEvents-BHPY5I08.js.map +1 -0
- package/dist/{tolerantWebAccess-BJqViq08.js → tolerantWebAccess-hDq9ZGXH.js} +53 -13
- package/dist/tolerantWebAccess-hDq9ZGXH.js.map +1 -0
- package/dist/{updateSeedRevokedAt-BL9Bg-G7.js → updateSeedRevokedAt-BMwBnlnC.js} +3 -3
- package/dist/{updateSeedRevokedAt-BL9Bg-G7.js.map → updateSeedRevokedAt-BMwBnlnC.js.map} +1 -1
- package/package.json +10 -12
- package/dist/BaseFileManager-BAlySv8w.js.map +0 -1
- package/dist/Item-Bf4kWKpH.js.map +0 -1
- package/dist/dist/BaseFileManager-BAlySv8w.d.ts.map +0 -1
- package/dist/dist/configurePlatform-CiOJ1R3q.d.ts.map +0 -1
- package/dist/errors-C1qUEZ7A.js.map +0 -1
- package/dist/index-BVBmz_cc.js.map +0 -1
- package/dist/index-CYGWPoOx.js.map +0 -1
- package/dist/index-D0V-mjCV.js.map +0 -1
- package/dist/index-DmTtj1nk.js.map +0 -1
- package/dist/index.browser-CUmBVYen.js.map +0 -1
- package/dist/index.node-CYPemH-t.js.map +0 -1
- package/dist/tabEvents-CaVmngqr.js.map +0 -1
- package/dist/tolerantWebAccess-BJqViq08.js.map +0 -1
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { w as writeNextSchemaVersion, o as applySchemaFile } from './errors-
|
|
2
|
-
import { a7 as convertTxIdToImage, x as normalizePublisher, m as generateId, n as normalizeDataType, j as findSeedRow, w as writeInBatches, a0 as INTERNAL_PROPERTY_NAMES, i as isDataType, M as ModelPropertyDataTypes, r as resolveModelRecord } from './tabEvents-
|
|
3
|
-
import './property-
|
|
4
|
-
import { B as BaseDb, v as versions, s as seeds, m as metadata, d as models, l as properties, w as BaseFileManager } from './BaseFileManager-
|
|
5
|
-
import { am as getStorageTransactionIdForSeedUid, an as latestVersionOrder, ao as otherVersionRowsWithUid, ap as mergeVersionRowInto, M as isVersionRevoked, aq as findMetadataPropertyByName, N as readModelMetadataProperties, S as parseListPropertyValueFromStorage, L as getLatestPublishedVersionRow, ar as resolvePublisherFromSeedRow } from './Item-
|
|
1
|
+
import { w as writeNextSchemaVersion, o as applySchemaFile } from './errors-DpC9W4i3.js';
|
|
2
|
+
import { a7 as convertTxIdToImage, x as normalizePublisher, m as generateId, n as normalizeDataType, j as findSeedRow, V as resolveUploadMimeType, R as getExtensionForMimeType, w as writeInBatches, a0 as INTERNAL_PROPERTY_NAMES, i as isDataType, M as ModelPropertyDataTypes, r as resolveModelRecord } from './tabEvents-BHPY5I08.js';
|
|
3
|
+
import './property-QjljUeb9.js';
|
|
4
|
+
import { B as BaseDb, v as versions, s as seeds, m as metadata, d as models, l as properties, w as BaseFileManager } from './BaseFileManager-DLou1TZS.js';
|
|
5
|
+
import { am as getStorageTransactionIdForSeedUid, an as latestVersionOrder, ao as otherVersionRowsWithUid, ap as mergeVersionRowInto, M as isVersionRevoked, aq as findMetadataPropertyByName, N as readModelMetadataProperties, S as parseListPropertyValueFromStorage, L as getLatestPublishedVersionRow, ar as storedValueKind, ac as storageSeedTransactionId, as as resolveStorageDisplay, at as resolvePublisherFromSeedRow } from './Item-CXLcIHsi.js';
|
|
6
6
|
import { eq, and, inArray, or, isNull } from 'drizzle-orm';
|
|
7
|
-
import { classifyMediaRef, BaseArweaveClient } from '@seedprotocol/arweave';
|
|
7
|
+
import { classifyMediaRef, BaseArweaveClient, resolveSeedIdsFromRefString, normalizeRelationPropertyValue, getPublicArweaveRawUrl } from '@seedprotocol/arweave';
|
|
8
8
|
import 'pluralize';
|
|
9
|
-
import { isPlaceholderUid, isValidEasAttestationUid, normalizeBytes32Hex } from '@seedprotocol/eas';
|
|
10
|
-
import './Schema-
|
|
11
|
-
import '
|
|
12
|
-
import './
|
|
13
|
-
import './
|
|
14
|
-
import './
|
|
15
|
-
import './
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
9
|
+
import { isPlaceholderUid, isValidEasAttestationUid, normalizeBytes32Hex, getEasReadChainId, getEasChainDeployment, getEasAttestationExplorerUrl } from '@seedprotocol/eas';
|
|
10
|
+
import './Schema-BeUyEmte.js';
|
|
11
|
+
import { rewriteHtmlUrls, parseArchiveDocument, dublinCoreXml, premisXml, digestHex, createBag } from '@seedprotocol/archive';
|
|
12
|
+
import { g as getPublishGraph } from './publishGraph-CP8IROkb.js';
|
|
13
|
+
import { r as resolveItemStorageChildFile, S as SEED_PROPERTY_REF_PREFIX, f as findEmbeddedImageFilePath, g as getPublishUploadSources } from './getPublishUploads-BdZmYCo2.js';
|
|
14
|
+
import './browserSupport-C64rX-2I.js';
|
|
15
|
+
import './updateSeedRevokedAt-BMwBnlnC.js';
|
|
16
|
+
import './ModelProperty-B3mfR6u4.js';
|
|
17
|
+
import './eas-DpHg66jR.js';
|
|
18
|
+
import './getPublishPendingDiff-D__9bh6d.js';
|
|
19
|
+
import { g as getPropertyClear } from './getPublishPayload-yidQCgY_.js';
|
|
19
20
|
import debug from 'debug';
|
|
20
21
|
|
|
21
22
|
/** Classification and feed-field helpers live in `@seedprotocol/arweave`; resolving needs the local DB and files. */
|
|
@@ -379,6 +380,387 @@ async function toAttestedRefValue(appDb, raw, kind, resolvedSeedUids) {
|
|
|
379
380
|
return value === raw ? undefined : value;
|
|
380
381
|
}
|
|
381
382
|
|
|
383
|
+
const getMetadata = async (props) => {
|
|
384
|
+
const appDb = BaseDb.getAppDb();
|
|
385
|
+
let storageTransactionId;
|
|
386
|
+
if (props) {
|
|
387
|
+
storageTransactionId = props.storageTransactionId;
|
|
388
|
+
}
|
|
389
|
+
const whereClauses = [];
|
|
390
|
+
if (storageTransactionId) {
|
|
391
|
+
whereClauses.push(eq(metadata.propertyName, 'storageTransactionId'));
|
|
392
|
+
whereClauses.push(eq(metadata.propertyValue, storageTransactionId));
|
|
393
|
+
}
|
|
394
|
+
const metadataRows = await appDb
|
|
395
|
+
.select()
|
|
396
|
+
.from(metadata)
|
|
397
|
+
.where(and(...whereClauses));
|
|
398
|
+
if (!metadataRows || metadataRows.length === 0) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
return metadataRows[0];
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
/** The item can't be exported as it is. `code` says why. */
|
|
405
|
+
class ArchiveExportError extends Error {
|
|
406
|
+
constructor(code, message) {
|
|
407
|
+
super(message);
|
|
408
|
+
this.name = 'ArchiveExportError';
|
|
409
|
+
this.code = code;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const ARWEAVE_TX_ID = /^[a-z0-9_-]{43}$/i;
|
|
413
|
+
const SOFTWARE_AGENT = '@seedprotocol/sdk exportArchive (https://github.com/JournoLabs/seed-protocol-sdk)';
|
|
414
|
+
const isoFromMs = (ms) => typeof ms === 'number' && Number.isFinite(ms) && ms > 0 ? new Date(ms).toISOString() : undefined;
|
|
415
|
+
const toBytes = async (data) => typeof Blob !== 'undefined' && data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : new Uint8Array(data);
|
|
416
|
+
const readBytes = async (filePath) => toBytes(await BaseFileManager.readFileAsBuffer(filePath));
|
|
417
|
+
/** The Arweave transaction id a gateway URL serves (`https://<host>/<tx>` or `/raw/<tx>`), if it is one. */
|
|
418
|
+
function arweaveTxIdOfUrl(url) {
|
|
419
|
+
try {
|
|
420
|
+
const parsed = new URL(url);
|
|
421
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')
|
|
422
|
+
return undefined;
|
|
423
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
424
|
+
const last = segments[segments.length - 1];
|
|
425
|
+
const isTxPath = segments.length === 1 || (segments.length === 2 && segments[0] === 'raw');
|
|
426
|
+
return isTxPath && last && ARWEAVE_TX_ID.test(last) ? last : undefined;
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const hasValue = (value) => value != null && value !== '';
|
|
433
|
+
/** A saved local value that no attestation backs: the bag would mix it with the published record. */
|
|
434
|
+
const isUnpublishedEdit = (property) => {
|
|
435
|
+
const row = property.row;
|
|
436
|
+
return !!row && !property.deferred && !row.uid && row.derivedFromUid == null && hasValue(row.propertyValue);
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* Builds the bag for `item`'s current published state:
|
|
440
|
+
*
|
|
441
|
+
* - `data/index.html` (or `data/<property>.html` when the model has several Html properties): the
|
|
442
|
+
* Html with references to files in the bag rewritten to relative paths.
|
|
443
|
+
* - `data/source/<property>.html`: each Html exactly as published.
|
|
444
|
+
* - `data/assets/<sha256>.<ext>`: Images, Files and images the Html references.
|
|
445
|
+
* - `data/item.json`: every property's value, attestation uid and Arweave transaction.
|
|
446
|
+
* - `metadata/dc.xml` and `metadata/premis.xml`.
|
|
447
|
+
*
|
|
448
|
+
* Throws {@link ArchiveExportError} `not_published` for an item without a live published version,
|
|
449
|
+
* and `unpublished_changes` when a property holds a saved value that isn't published yet.
|
|
450
|
+
* A file that can't be read or downloaded is left out and reported in `omitted`, not thrown.
|
|
451
|
+
*/
|
|
452
|
+
async function exportArchive(item, options = {}) {
|
|
453
|
+
const fetch = options.fetch ?? true;
|
|
454
|
+
const now = options.baggingDate ?? new Date();
|
|
455
|
+
const graph = await getPublishGraph(item);
|
|
456
|
+
const root = graph.root;
|
|
457
|
+
const seedRow = await findSeedRow({ localId: root.seedLocalId });
|
|
458
|
+
const seedUid = root.seedUid;
|
|
459
|
+
const version = await getLatestPublishedVersionRow(root.seedLocalId);
|
|
460
|
+
if (!seedUid || !isValidEasAttestationUid(seedUid) || seedRow?.revokedAt || !version) {
|
|
461
|
+
throw new ArchiveExportError('not_published', `${root.modelName} ${root.seedLocalId} has no live published version`);
|
|
462
|
+
}
|
|
463
|
+
const unpublished = root.properties.filter(isUnpublishedEdit).map((p) => p.key);
|
|
464
|
+
if (unpublished.length > 0) {
|
|
465
|
+
throw new ArchiveExportError('unpublished_changes', `${root.modelName} ${root.seedLocalId} has unpublished changes to ${unpublished.join(', ')}; publish them first`);
|
|
466
|
+
}
|
|
467
|
+
const chainId = getEasReadChainId();
|
|
468
|
+
const chain = getEasChainDeployment(chainId);
|
|
469
|
+
const explorerUrl = (uid) => (chain ? getEasAttestationExplorerUrl(chain, uid) : undefined);
|
|
470
|
+
const schemaName = item.getService?.().getSnapshot().context.schemaName;
|
|
471
|
+
const attester = seedRow?.publisher ?? undefined;
|
|
472
|
+
const omitted = [];
|
|
473
|
+
const payload = [];
|
|
474
|
+
const fileInfo = new Map();
|
|
475
|
+
const assetPathByTx = new Map();
|
|
476
|
+
const assetPathByProperty = new Map();
|
|
477
|
+
const htmlSources = [];
|
|
478
|
+
const properties = {};
|
|
479
|
+
const addAsset = (bytes, mimeType, arweaveTransactionId) => {
|
|
480
|
+
const ext = getExtensionForMimeType(mimeType);
|
|
481
|
+
const path = `assets/${digestHex('sha256', bytes)}${ext ? `.${ext}` : ''}`;
|
|
482
|
+
if (!payload.some((f) => f.path === path)) {
|
|
483
|
+
payload.push({ path, bytes });
|
|
484
|
+
fileInfo.set(path, { mimeType, arweaveTransactionId });
|
|
485
|
+
}
|
|
486
|
+
if (arweaveTransactionId)
|
|
487
|
+
assetPathByTx.set(arweaveTransactionId, path);
|
|
488
|
+
return path;
|
|
489
|
+
};
|
|
490
|
+
for (const property of root.properties) {
|
|
491
|
+
const { key, definition: def, kind, row } = property;
|
|
492
|
+
const dataType = normalizeDataType(def.dataType) ?? String(def.dataType);
|
|
493
|
+
const entry = {
|
|
494
|
+
dataType,
|
|
495
|
+
attestationUid: row?.uid ?? row?.derivedFromUid ?? undefined,
|
|
496
|
+
attestedAt: isoFromMs(row?.attestationCreatedAt),
|
|
497
|
+
};
|
|
498
|
+
properties[key] = entry;
|
|
499
|
+
if (kind === 'basic' || kind === 'storageTransaction') {
|
|
500
|
+
entry.value = row?.propertyValue ?? null;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (kind === 'relation' || kind === 'list') {
|
|
504
|
+
entry.value = kind === 'list' ? property.refs.map((r) => r.ref) : (property.refs[0]?.ref ?? null);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (kind === 'itemStorage') {
|
|
508
|
+
const { filePath } = await resolveItemStorageChildFile(root, property);
|
|
509
|
+
if (!filePath) {
|
|
510
|
+
if (row && hasValue(row.propertyValue))
|
|
511
|
+
omitted.push({ property: key, reason: 'its file is not on this device' });
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const bytes = await readBytes(filePath);
|
|
515
|
+
if (dataType === 'Html') {
|
|
516
|
+
htmlSources.push({ key, text: new TextDecoder().decode(bytes) });
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
const mimeType = resolveUploadMimeType({ fileName: filePath, bytes }) ?? 'application/octet-stream';
|
|
520
|
+
entry.file = addAsset(bytes, mimeType);
|
|
521
|
+
assetPathByProperty.set(key, entry.file);
|
|
522
|
+
}
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
// storageSeed: the value is a storage seed whose own row records the Arweave transaction.
|
|
526
|
+
if (!row || !hasValue(row.propertyValue))
|
|
527
|
+
continue;
|
|
528
|
+
const storageKind = storedValueKind(def, row);
|
|
529
|
+
if (!storageKind || storageKind === 'itemStorage') {
|
|
530
|
+
omitted.push({ property: key, reason: `${dataType} storage seeds are not exported yet` });
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
const arweaveTransactionId = await storageSeedTransactionId(resolveSeedIdsFromRefString(normalizeRelationPropertyValue(row.propertyValue) ?? ''));
|
|
534
|
+
if (arweaveTransactionId)
|
|
535
|
+
entry.arweaveTransactionId = arweaveTransactionId;
|
|
536
|
+
const display = await resolveStorageDisplay(storageKind, row, { fetch });
|
|
537
|
+
if (storageKind === 'html') {
|
|
538
|
+
const text = display.filePath ? await BaseFileManager.readFileAsString(display.filePath) : display.renderValue;
|
|
539
|
+
if (text === undefined) {
|
|
540
|
+
omitted.push({ property: key, reason: 'its Html could not be read or downloaded' });
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
htmlSources.push({ key, text, arweaveTransactionId });
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
if (!display.filePath) {
|
|
547
|
+
omitted.push({ property: key, reason: 'its file could not be read or downloaded' });
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
const bytes = await readBytes(display.filePath);
|
|
551
|
+
const mimeType = resolveUploadMimeType({ fileName: display.filePath, bytes }) ?? 'application/octet-stream';
|
|
552
|
+
entry.file = addAsset(bytes, mimeType, arweaveTransactionId);
|
|
553
|
+
assetPathByProperty.set(key, entry.file);
|
|
554
|
+
}
|
|
555
|
+
/** The bag path for an image the Html names by transaction id but no property holds (an embedded image). */
|
|
556
|
+
const embeddedAssetPath = async (txId) => {
|
|
557
|
+
const known = assetPathByTx.get(txId);
|
|
558
|
+
if (known)
|
|
559
|
+
return known;
|
|
560
|
+
const imageRow = await getMetadata({ storageTransactionId: txId });
|
|
561
|
+
let filePath = imageRow?.seedLocalId ? await findEmbeddedImageFilePath(imageRow.seedLocalId) : undefined;
|
|
562
|
+
if (!filePath) {
|
|
563
|
+
const display = await resolveStorageDisplay('image', { refResolvedValue: txId, localStorageDir: '/images' }, { fetch });
|
|
564
|
+
filePath = display.filePath;
|
|
565
|
+
}
|
|
566
|
+
if (!filePath)
|
|
567
|
+
return undefined;
|
|
568
|
+
const bytes = await readBytes(filePath);
|
|
569
|
+
const mimeType = resolveUploadMimeType({ fileName: filePath, bytes }) ?? 'application/octet-stream';
|
|
570
|
+
return addAsset(bytes, mimeType, txId);
|
|
571
|
+
};
|
|
572
|
+
const encoder = new TextEncoder();
|
|
573
|
+
for (const html of htmlSources) {
|
|
574
|
+
const targets = new Map();
|
|
575
|
+
// Collect first: rewriteHtmlUrls takes a synchronous mapping.
|
|
576
|
+
rewriteHtmlUrls(html.text, (url) => {
|
|
577
|
+
targets.set(url, url);
|
|
578
|
+
return undefined;
|
|
579
|
+
});
|
|
580
|
+
for (const url of targets.keys()) {
|
|
581
|
+
if (url.startsWith(SEED_PROPERTY_REF_PREFIX)) {
|
|
582
|
+
const path = assetPathByProperty.get(url.slice(SEED_PROPERTY_REF_PREFIX.length));
|
|
583
|
+
if (path)
|
|
584
|
+
targets.set(url, path);
|
|
585
|
+
else
|
|
586
|
+
targets.delete(url);
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
const txId = arweaveTxIdOfUrl(url);
|
|
590
|
+
const path = txId ? await embeddedAssetPath(txId) : undefined;
|
|
591
|
+
if (path)
|
|
592
|
+
targets.set(url, path);
|
|
593
|
+
else {
|
|
594
|
+
targets.delete(url);
|
|
595
|
+
if (txId)
|
|
596
|
+
omitted.push({ property: html.key, reason: `references ${url}, which is not in the bag` });
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const rewritten = rewriteHtmlUrls(html.text, (url) => targets.get(url));
|
|
600
|
+
const viewPath = htmlSources.length === 1 ? 'index.html' : `${html.key}.html`;
|
|
601
|
+
payload.push({ path: viewPath, bytes: encoder.encode(rewritten) });
|
|
602
|
+
fileInfo.set(viewPath, { mimeType: 'text/html' });
|
|
603
|
+
const sourcePath = `source/${html.key}.html`;
|
|
604
|
+
payload.push({ path: sourcePath, bytes: encoder.encode(html.text) });
|
|
605
|
+
fileInfo.set(sourcePath, { mimeType: 'text/html', arweaveTransactionId: html.arweaveTransactionId });
|
|
606
|
+
properties[html.key].file = sourcePath;
|
|
607
|
+
}
|
|
608
|
+
const itemJson = {
|
|
609
|
+
seedUid,
|
|
610
|
+
versionUid: version.uid,
|
|
611
|
+
schemaName,
|
|
612
|
+
modelName: root.modelName,
|
|
613
|
+
chain: { id: chainId, name: chain?.name },
|
|
614
|
+
attester,
|
|
615
|
+
properties,
|
|
616
|
+
omitted,
|
|
617
|
+
};
|
|
618
|
+
payload.push({ path: 'item.json', bytes: encoder.encode(`${JSON.stringify(itemJson, null, 2)}\n`) });
|
|
619
|
+
fileInfo.set('item.json', { mimeType: 'application/json' });
|
|
620
|
+
// Descriptive metadata comes from the archive document, so nothing is guessed from property names.
|
|
621
|
+
const primary = htmlSources[0];
|
|
622
|
+
const doc = primary ? parseArchiveDocument(primary.text) : undefined;
|
|
623
|
+
const versionDate = isoFromMs(version.attestationCreatedAt);
|
|
624
|
+
const dc = dublinCoreXml({
|
|
625
|
+
title: doc?.name,
|
|
626
|
+
creator: doc?.authors,
|
|
627
|
+
description: doc?.summary,
|
|
628
|
+
date: doc?.published ?? versionDate?.slice(0, 10),
|
|
629
|
+
type: 'Text',
|
|
630
|
+
format: primary ? 'text/html' : undefined,
|
|
631
|
+
identifier: [seedUid, explorerUrl(seedUid)].filter((v) => !!v),
|
|
632
|
+
source: doc?.url,
|
|
633
|
+
});
|
|
634
|
+
const premis = premisXml({
|
|
635
|
+
objects: [
|
|
636
|
+
{
|
|
637
|
+
kind: 'intellectualEntity',
|
|
638
|
+
identifiers: [
|
|
639
|
+
{ type: 'Seed Protocol seed UID', value: seedUid },
|
|
640
|
+
{ type: 'Seed Protocol version UID', value: version.uid },
|
|
641
|
+
],
|
|
642
|
+
},
|
|
643
|
+
...payload.map((file) => {
|
|
644
|
+
const info = fileInfo.get(file.path);
|
|
645
|
+
return {
|
|
646
|
+
kind: 'file',
|
|
647
|
+
identifiers: [{ type: 'bag path', value: `data/${file.path}` }],
|
|
648
|
+
fixity: { 'SHA-256': digestHex('sha256', file.bytes), 'SHA-512': digestHex('sha512', file.bytes) },
|
|
649
|
+
size: file.bytes.byteLength,
|
|
650
|
+
formatName: info?.mimeType ?? 'application/octet-stream',
|
|
651
|
+
originalName: info?.arweaveTransactionId ? getPublicArweaveRawUrl(info.arweaveTransactionId) : undefined,
|
|
652
|
+
};
|
|
653
|
+
}),
|
|
654
|
+
],
|
|
655
|
+
events: [...(await historyEvents(root.seedLocalId, seedUid, version, attester)), ...bagEvents(now, seedUid)],
|
|
656
|
+
agents: [
|
|
657
|
+
...(attester
|
|
658
|
+
? [{ identifiers: [{ type: 'EVM address', value: attester }], note: `EAS attester on chain ${chainId}` }]
|
|
659
|
+
: []),
|
|
660
|
+
{ identifiers: [{ type: 'software', value: '@seedprotocol/sdk' }], name: '@seedprotocol/sdk', type: 'software' },
|
|
661
|
+
],
|
|
662
|
+
});
|
|
663
|
+
const info = [];
|
|
664
|
+
if (options.sourceOrganization)
|
|
665
|
+
info.push(['Source-Organization', options.sourceOrganization]);
|
|
666
|
+
info.push(['External-Identifier', seedUid]);
|
|
667
|
+
if (doc?.name)
|
|
668
|
+
info.push(['External-Description', doc.name]);
|
|
669
|
+
info.push(['Seed-Uid', seedUid], ['Seed-Version-Uid', version.uid], ['Seed-Model', root.modelName]);
|
|
670
|
+
if (schemaName)
|
|
671
|
+
info.push(['Seed-Schema', schemaName]);
|
|
672
|
+
info.push(['EAS-Chain-Id', String(chainId)]);
|
|
673
|
+
if (chain?.name)
|
|
674
|
+
info.push(['EAS-Chain-Name', chain.name]);
|
|
675
|
+
if (attester)
|
|
676
|
+
info.push(['EAS-Attester', attester]);
|
|
677
|
+
const bag = createBag({
|
|
678
|
+
payload,
|
|
679
|
+
tagFiles: [
|
|
680
|
+
{ path: 'metadata/dc.xml', bytes: encoder.encode(dc) },
|
|
681
|
+
{ path: 'metadata/premis.xml', bytes: encoder.encode(premis) },
|
|
682
|
+
],
|
|
683
|
+
info,
|
|
684
|
+
baggingDate: now,
|
|
685
|
+
softwareAgent: SOFTWARE_AGENT,
|
|
686
|
+
});
|
|
687
|
+
return { bag, omitted };
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* The seed's attested history: its first live Version as creation, later Versions and property
|
|
691
|
+
* attestations made after the current Version (patches) as modifications. Attestations without
|
|
692
|
+
* a recorded time are left out, since PREMIS events need one.
|
|
693
|
+
*/
|
|
694
|
+
async function historyEvents(seedLocalId, seedUid, current, attester) {
|
|
695
|
+
const db = BaseDb.getAppDb();
|
|
696
|
+
const agents = attester ? [{ type: 'EVM address', value: attester, role: 'attester' }] : [];
|
|
697
|
+
const objects = [{ type: 'Seed Protocol seed UID', value: seedUid }];
|
|
698
|
+
const versionRows = (await db
|
|
699
|
+
.select({ uid: versions.uid, attestationCreatedAt: versions.attestationCreatedAt, revokedAt: versions.revokedAt })
|
|
700
|
+
.from(versions)
|
|
701
|
+
.where(eq(versions.seedLocalId, seedLocalId)))
|
|
702
|
+
.filter((v) => isValidEasAttestationUid(v.uid) && v.attestationCreatedAt)
|
|
703
|
+
.sort((a, b) => a.attestationCreatedAt - b.attestationCreatedAt);
|
|
704
|
+
const events = versionRows.map((v, index) => ({
|
|
705
|
+
identifier: { type: 'EAS attestation UID', value: v.uid },
|
|
706
|
+
type: index === 0 ? 'creation' : 'modification',
|
|
707
|
+
dateTime: isoFromMs(v.attestationCreatedAt),
|
|
708
|
+
detail: index === 0 ? 'First Version attested' : 'New Version attested',
|
|
709
|
+
outcome: 'success',
|
|
710
|
+
outcomeNote: v.revokedAt ? `Version revoked at ${new Date(v.revokedAt * 1000).toISOString()}` : undefined,
|
|
711
|
+
agents,
|
|
712
|
+
objects,
|
|
713
|
+
}));
|
|
714
|
+
if (current.attestationCreatedAt) {
|
|
715
|
+
const patches = (await db
|
|
716
|
+
.select({ uid: metadata.uid, propertyName: metadata.propertyName, attestationCreatedAt: metadata.attestationCreatedAt })
|
|
717
|
+
.from(metadata)
|
|
718
|
+
.where(and(eq(metadata.seedLocalId, seedLocalId), eq(metadata.versionUid, current.uid))));
|
|
719
|
+
for (const row of patches) {
|
|
720
|
+
if (!isValidEasAttestationUid(row.uid) || !row.attestationCreatedAt)
|
|
721
|
+
continue;
|
|
722
|
+
if (row.attestationCreatedAt <= current.attestationCreatedAt)
|
|
723
|
+
continue;
|
|
724
|
+
events.push({
|
|
725
|
+
identifier: { type: 'EAS attestation UID', value: row.uid },
|
|
726
|
+
type: 'modification',
|
|
727
|
+
dateTime: isoFromMs(row.attestationCreatedAt),
|
|
728
|
+
detail: `Property ${row.propertyName} attested again on Version ${current.uid}`,
|
|
729
|
+
outcome: 'success',
|
|
730
|
+
agents,
|
|
731
|
+
objects,
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return events.sort((a, b) => a.dateTime.localeCompare(b.dateTime));
|
|
736
|
+
}
|
|
737
|
+
/** The bag's own events: its checksums and the package itself. */
|
|
738
|
+
const bagEvents = (now, seedUid) => {
|
|
739
|
+
const agents = [{ type: 'software', value: '@seedprotocol/sdk', role: 'executing program' }];
|
|
740
|
+
const objects = [{ type: 'Seed Protocol seed UID', value: seedUid }];
|
|
741
|
+
const dateTime = now.toISOString();
|
|
742
|
+
return [
|
|
743
|
+
{
|
|
744
|
+
identifier: { type: 'bag event', value: `message-digest-${dateTime}` },
|
|
745
|
+
type: 'message digest calculation',
|
|
746
|
+
dateTime,
|
|
747
|
+
detail: 'SHA-256 and SHA-512 of every payload and tag file',
|
|
748
|
+
outcome: 'success',
|
|
749
|
+
agents,
|
|
750
|
+
objects,
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
identifier: { type: 'bag event', value: `package-${dateTime}` },
|
|
754
|
+
type: 'information package creation',
|
|
755
|
+
dateTime,
|
|
756
|
+
detail: 'BagIt 1.0 bag written by exportArchive',
|
|
757
|
+
outcome: 'success',
|
|
758
|
+
agents,
|
|
759
|
+
objects,
|
|
760
|
+
},
|
|
761
|
+
];
|
|
762
|
+
};
|
|
763
|
+
|
|
382
764
|
const getVersionsForSeedUid = async (seedUid) => {
|
|
383
765
|
if (!seedUid)
|
|
384
766
|
return [];
|
|
@@ -790,8 +1172,8 @@ async function renameModelProperty(schemaName, modelName, oldPropertyName, newPr
|
|
|
790
1172
|
});
|
|
791
1173
|
logger(`Renamed property ${oldPropertyName} to ${newPropertyName} in schema ${schemaName} v${schemaFile.version}`);
|
|
792
1174
|
// Item values follow the property by property_id (decision D4); only pending edits name it
|
|
793
|
-
const _mod_0 = await import('./tabEvents-
|
|
794
|
-
const _ns_0 = _mod_0.
|
|
1175
|
+
const _mod_0 = await import('./tabEvents-BHPY5I08.js');
|
|
1176
|
+
const _ns_0 = _mod_0.bk;
|
|
795
1177
|
const { renamePendingWritesForProperty } = _ns_0;
|
|
796
1178
|
await renamePendingWritesForProperty(modelName, oldPropertyName, newPropertyName);
|
|
797
1179
|
// Applied after a delay: applying posts to BroadcastChannel and causes React invalidates, and
|
|
@@ -813,5 +1195,5 @@ var updateSchema = /*#__PURE__*/Object.freeze({
|
|
|
813
1195
|
updateModelProperties: updateModelProperties
|
|
814
1196
|
});
|
|
815
1197
|
|
|
816
|
-
export { applyPropertyAttestationUidsFromPublish as a,
|
|
817
|
-
//# sourceMappingURL=index-
|
|
1198
|
+
export { ArchiveExportError as A, applyPropertyAttestationUidsFromPublish as a, exportArchive as b, getMetadataAttestationUidsForSeedUid as c, getSeedPublishState as d, estimateDataUriByteLength as e, getUnpublishedRelatedItems as f, getAttesterForSeed as g, getVersionsForSeedUid as h, resolveMediaRef as i, updateVersionUid as j, updateSchema as k, markPropertyAttestationsRetracted as m, renameModelProperty as r, summarizePublishWork as s, updateModelProperties as u };
|
|
1199
|
+
//# sourceMappingURL=index-CVYB2g7a.js.map
|