@seedprotocol/sdk 0.4.19 → 0.4.21
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/{ArweaveClient-CAdWVQnJ.js → ArweaveClient-Cz9ZLiEV.js} +3 -3
- package/dist/{ArweaveClient-CAdWVQnJ.js.map → ArweaveClient-Cz9ZLiEV.js.map} +1 -1
- package/dist/{ArweaveClient-V62RJhsZ.js → ArweaveClient-DxpJnJXU.js} +3 -3
- package/dist/{ArweaveClient-V62RJhsZ.js.map → ArweaveClient-DxpJnJXU.js.map} +1 -1
- package/dist/{Db-DS2GBY6h.js → Db-CXwQVLZv.js} +41 -4
- package/dist/Db-CXwQVLZv.js.map +1 -0
- package/dist/{Db-8N3-le9a.js → Db-DkTBncAM.js} +4 -4
- package/dist/{Db-8N3-le9a.js.map → Db-DkTBncAM.js.map} +1 -1
- package/dist/{EasClient-D1eibg8b.js → EasClient-DjpbHjU9.js} +2 -2
- package/dist/{EasClient-D1eibg8b.js.map → EasClient-DjpbHjU9.js.map} +1 -1
- package/dist/{EasClient-nOmY5meW.js → EasClient-JYkmHxu1.js} +2 -2
- package/dist/{EasClient-nOmY5meW.js.map → EasClient-JYkmHxu1.js.map} +1 -1
- package/dist/{FileManager-DSTAwkqw.js → FileManager-CKyoLrBP.js} +2 -2
- package/dist/{FileManager-DSTAwkqw.js.map → FileManager-CKyoLrBP.js.map} +1 -1
- package/dist/{FileManager-Cze8qmS1.js → FileManager-DHnyb040.js} +34 -5
- package/dist/FileManager-DHnyb040.js.map +1 -0
- package/dist/{ModelProperty-ChevZoUy.js → ModelProperty-DWtv9fQr.js} +24 -24
- package/dist/{ModelProperty-ChevZoUy.js.map → ModelProperty-DWtv9fQr.js.map} +1 -1
- package/dist/{PathResolver-3TuYA9yv.js → PathResolver-Ce4K9acQ.js} +2 -2
- package/dist/{PathResolver-3TuYA9yv.js.map → PathResolver-Ce4K9acQ.js.map} +1 -1
- package/dist/{PathResolver-C5gj9EU2.js → PathResolver-pmw--Ea2.js} +2 -2
- package/dist/{PathResolver-C5gj9EU2.js.map → PathResolver-pmw--Ea2.js.map} +1 -1
- package/dist/{QueryClient-BGv6JOls.js → QueryClient-OUjfvY3g.js} +2 -2
- package/dist/{QueryClient-BGv6JOls.js.map → QueryClient-OUjfvY3g.js.map} +1 -1
- package/dist/{QueryClient-By2vdhIz.js → QueryClient-unspcsWa.js} +2 -2
- package/dist/{QueryClient-By2vdhIz.js.map → QueryClient-unspcsWa.js.map} +1 -1
- package/dist/{Schema-BQ5W3aOW.js → Schema-CqqcEexA.js} +38 -38
- package/dist/{Schema-BQ5W3aOW.js.map → Schema-CqqcEexA.js.map} +1 -1
- package/dist/{SchemaValidationService-DQx83Cte.js → SchemaValidationService-Cb-b4kpD.js} +2 -2
- package/dist/{SchemaValidationService-DQx83Cte.js.map → SchemaValidationService-Cb-b4kpD.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-CMsU83q9.js → backfillMetadataPropertyIds-CRyRez3h.js} +2 -2
- package/dist/{backfillMetadataPropertyIds-CMsU83q9.js.map → backfillMetadataPropertyIds-CRyRez3h.js.map} +1 -1
- package/dist/cjs/{ModelProperty-Cuj839nX.js → ModelProperty-sNx_ZQZX.js} +17 -17
- package/dist/cjs/{ModelProperty-Cuj839nX.js.map → ModelProperty-sNx_ZQZX.js.map} +1 -1
- package/dist/cjs/{Schema-TFe24NNG.js → Schema-B4RRA-0g.js} +20 -20
- package/dist/cjs/{Schema-TFe24NNG.js.map → Schema-B4RRA-0g.js.map} +1 -1
- package/dist/cjs/{SchemaValidationService-DVQrRpse.js → SchemaValidationService-DCflhpcI.js} +2 -2
- package/dist/cjs/{SchemaValidationService-DVQrRpse.js.map → SchemaValidationService-DCflhpcI.js.map} +1 -1
- package/dist/cjs/{backfillMetadataPropertyIds-BiXK4hT1.js → backfillMetadataPropertyIds-DhAXAuSf.js} +2 -2
- package/dist/cjs/{backfillMetadataPropertyIds-BiXK4hT1.js.map → backfillMetadataPropertyIds-DhAXAuSf.js.map} +1 -1
- package/dist/cjs/{getItem-FgLv9abh.js → getItem-lyM2x5pT.js} +5 -3
- package/dist/cjs/getItem-lyM2x5pT.js.map +1 -0
- package/dist/cjs/{getPublishPayload-h_Rz8nVX.js → getPublishPayload-DP2fm4q8.js} +125 -26
- package/dist/cjs/getPublishPayload-DP2fm4q8.js.map +1 -0
- package/dist/cjs/{getPublishUploads-DdSwst2x.js → getPublishUploads-DdVy-5fK.js} +69 -23
- package/dist/cjs/getPublishUploads-DdVy-5fK.js.map +1 -0
- package/dist/cjs/{getSegmentedItemProperties-Bu4P_MG8.js → getSegmentedItemProperties-DtHofn5i.js} +3 -3
- package/dist/cjs/{getSegmentedItemProperties-Bu4P_MG8.js.map → getSegmentedItemProperties-DtHofn5i.js.map} +1 -1
- package/dist/cjs/{index-pyKmk9hA.js → index-D1qR8xnb.js} +1055 -388
- package/dist/cjs/index-D1qR8xnb.js.map +1 -0
- package/dist/cjs/{index-CKJeh6ic.js → index-DTkoTvcq.js} +5 -3
- package/dist/cjs/index-DTkoTvcq.js.map +1 -0
- package/dist/cjs/{ownership-gfm5thj7.js → ownership-DanM_n8E.js} +4 -4
- package/dist/cjs/ownership-DanM_n8E.js.map +1 -0
- package/dist/cjs/{property-Dw0b_Sf8.js → property-BQokoaRe.js} +6 -4
- package/dist/cjs/{property-Dw0b_Sf8.js.map → property-BQokoaRe.js.map} +1 -1
- package/dist/db/drizzle/drizzle/0011_normalize_placeholder_uids.sql +9 -0
- package/dist/db/drizzle/drizzle/0012_html_embedded_image_co_publish.sql +10 -0
- package/dist/db/drizzle/drizzle/meta/_journal.json +14 -0
- package/dist/{getItem-Bd9U9Yih.js → getItem-VI3QqdZH.js} +5 -3
- package/dist/getItem-VI3QqdZH.js.map +1 -0
- package/dist/{getPublishPayload-eJL7ktes.js → getPublishPayload-DpYwi-rd.js} +129 -30
- package/dist/getPublishPayload-DpYwi-rd.js.map +1 -0
- package/dist/{getPublishUploads-CKm5dsL6.js → getPublishUploads-DS2dQ4Ho.js} +69 -23
- package/dist/getPublishUploads-DS2dQ4Ho.js.map +1 -0
- package/dist/{getSegmentedItemProperties-B74LN_bz.js → getSegmentedItemProperties-Bz5B4DSA.js} +3 -3
- package/dist/{getSegmentedItemProperties-B74LN_bz.js.map → getSegmentedItemProperties-Bz5B4DSA.js.map} +1 -1
- package/dist/{index-BvZCYMxA.js → index-BrD_NNaX.js} +1056 -395
- package/dist/index-BrD_NNaX.js.map +1 -0
- package/dist/index-Cqf_DxkJ.js +19 -0
- package/dist/index-Cqf_DxkJ.js.map +1 -0
- package/dist/{index-BQv2k74p.js → index-DdzhrbkF.js} +3 -2
- package/dist/index-DdzhrbkF.js.map +1 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +528 -41
- package/dist/main.js.map +1 -1
- package/dist/node.js +10 -10
- package/dist/{ownership-tVhYQomL.js → ownership-BK6suksO.js} +4 -4
- package/dist/ownership-BK6suksO.js.map +1 -0
- package/dist/{property-BOdk-wW1.js → property-C63Ddzap.js} +6 -6
- package/dist/{property-BOdk-wW1.js.map → property-C63Ddzap.js.map} +1 -1
- package/dist/{queries-DBqVwEdv.js → queries-BGuWjEqt.js} +2 -2
- package/dist/{queries-DBqVwEdv.js.map → queries-BGuWjEqt.js.map} +1 -1
- package/dist/seedSchema/HtmlEmbeddedImageCoPublishSchema.ts +25 -0
- package/dist/seedSchema/index.ts +1 -0
- package/dist/src/Item/Item.d.ts +2 -2
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
- package/dist/src/Item/service/itemMachineSingle.d.ts +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +2 -2
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +1 -1
- package/dist/src/Model/Model.d.ts +1 -1
- package/dist/src/Model/index.d.ts +1 -0
- package/dist/src/Model/index.d.ts.map +1 -1
- package/dist/src/Model/service/modelMachine.d.ts +3 -3
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +2 -2
- package/dist/src/Schema/Schema.d.ts +1 -1
- package/dist/src/Schema/service/schemaMachine.d.ts +3 -3
- package/dist/src/browser/db/drizzleFiles.d.ts +3 -1
- package/dist/src/browser/db/drizzleFiles.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/client/events.d.ts +8 -0
- package/dist/src/client/events.d.ts.map +1 -0
- package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts +10 -0
- package/dist/src/db/read/batchLatestPublishedVersionBySeedLocalIds.d.ts.map +1 -0
- package/dist/src/db/read/getItem.d.ts.map +1 -1
- package/dist/src/db/read/getItemData.d.ts.map +1 -1
- package/dist/src/db/read/getItems.d.ts +9 -0
- package/dist/src/db/read/getItems.d.ts.map +1 -1
- package/dist/src/db/read/getLatestPublishedVersionRow.d.ts +11 -0
- package/dist/src/db/read/getLatestPublishedVersionRow.d.ts.map +1 -0
- package/dist/src/db/read/getMetadataAttestationUidsForSeedUid.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPendingDiff.d.ts +3 -3
- package/dist/src/db/read/getPublishPendingDiff.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts +17 -3
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getSeedPublishState.d.ts +21 -0
- package/dist/src/db/read/getSeedPublishState.d.ts.map +1 -0
- package/dist/src/db/read/subqueries/versionData.d.ts +7 -0
- package/dist/src/db/read/subqueries/versionData.d.ts.map +1 -1
- package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts +17 -0
- package/dist/src/db/write/applyPropertyAttestationUidsFromPublish.d.ts.map +1 -0
- package/dist/src/db/write/updateSeedUid.d.ts +3 -1
- package/dist/src/db/write/updateSeedUid.d.ts.map +1 -1
- package/dist/src/db/write/updateVersionUid.d.ts +3 -1
- package/dist/src/db/write/updateVersionUid.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/uploadApiVerification.d.ts +5 -1
- package/dist/src/helpers/ArweaveClient/uploadApiVerification.d.ts.map +1 -1
- package/dist/src/helpers/constants.d.ts +2 -0
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/easUid.d.ts +13 -0
- package/dist/src/helpers/easUid.d.ts.map +1 -0
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +55 -0
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -0
- package/dist/src/helpers/index.d.ts +2 -0
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/mediaRef.d.ts +72 -0
- package/dist/src/helpers/mediaRef.d.ts.map +1 -0
- package/dist/src/helpers/ownership.d.ts +2 -2
- package/dist/src/helpers/property/index.d.ts +30 -0
- package/dist/src/helpers/property/index.d.ts.map +1 -1
- package/dist/src/helpers/publishConfig.d.ts +3 -4
- package/dist/src/helpers/publishConfig.d.ts.map +1 -1
- package/dist/src/helpers/waitForEntityIdle.d.ts.map +1 -1
- package/dist/src/index.d.ts +14 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IItem.d.ts +2 -2
- package/dist/src/interfaces/IItem.d.ts.map +1 -1
- package/dist/src/seedSchema/HtmlEmbeddedImageCoPublishSchema.d.ts +122 -0
- package/dist/src/seedSchema/HtmlEmbeddedImageCoPublishSchema.d.ts.map +1 -0
- package/dist/src/seedSchema/index.d.ts +1 -0
- package/dist/src/seedSchema/index.d.ts.map +1 -1
- package/dist/src/services/write/writeProcessMachine.d.ts +1 -1
- package/dist/src/types/index.d.ts +6 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/item.d.ts +3 -0
- package/dist/src/types/item.d.ts.map +1 -1
- package/dist/src/types/machines.d.ts +2 -0
- package/dist/src/types/machines.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/Db-DS2GBY6h.js.map +0 -1
- package/dist/FileManager-Cze8qmS1.js.map +0 -1
- package/dist/cjs/getItem-FgLv9abh.js.map +0 -1
- package/dist/cjs/getPublishPayload-h_Rz8nVX.js.map +0 -1
- package/dist/cjs/getPublishUploads-DdSwst2x.js.map +0 -1
- package/dist/cjs/index-CKJeh6ic.js.map +0 -1
- package/dist/cjs/index-pyKmk9hA.js.map +0 -1
- package/dist/cjs/ownership-gfm5thj7.js.map +0 -1
- package/dist/getItem-Bd9U9Yih.js.map +0 -1
- package/dist/getPublishPayload-eJL7ktes.js.map +0 -1
- package/dist/getPublishUploads-CKm5dsL6.js.map +0 -1
- package/dist/index-BQv2k74p.js.map +0 -1
- package/dist/index-BvZCYMxA.js.map +0 -1
- package/dist/index-BxfqPvtu.js +0 -19
- package/dist/index-BxfqPvtu.js.map +0 -1
- package/dist/ownership-tVhYQomL.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { getPropertySchema } from './property-
|
|
2
|
+
import { p as BaseDb, al as versions, aL as isPlaceholderUid, aa as metadata, E as isValidEasAttestationUid, aM as normalizeBytes32Hex, G as getLatestPublishedVersionRow, s as seeds, O as parseListPropertyValueFromStorage, t as normalizeRelationPropertyValue, r as resolveSeedIdsFromRefString, b as ModelPropertyDataTypes, v as BaseFileManager, x as htmlEmbeddedImageCoPublish, u as Item, aN as getArweaveUrlForTransaction, aF as waitForEntityIdle, w as getContentHash } from './index-BrD_NNaX.js';
|
|
3
|
+
export { aO as ADDRESSES_PERSISTED_EVENT, y as BaseArweaveClient, aR as ClientManagerState, bf as DEFAULT_ARWEAVE_GATEWAYS, bg as DEFAULT_ARWEAVE_GRAPHQL_URL, be as DEFAULT_ARWEAVE_HOST, a5 as EasClient, W as INTERNAL_DATA_TYPES, aZ as ImageSize, ar as ItemProperty, aS as MachineIds, M as Model, aY as SEED_PROTOCOL_SCHEMA_NAME, bd as SeedModels, V as VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, a1 as appState, a8 as arweaveL1FinalizeJobs, b8 as classifyMediaRef, at as client, aT as createNewItem, bx as createSchema, as as eventEmitter, aE as generateId, bi as getAddressesForItemsFilter, bn as getArweaveUploadStatus, b3 as getCanonicalItemPropertiesFromEas, aQ as getClient, Q as getCorrectId, _ as getEasSchemaForItemProperty, b4 as getEasSchemaUidBySchemaName, bb as getFeedItemStringField, q as getGetAdditionalSyncAddresses, bt as getGetPublisherForNewSeeds, b2 as getItemPropertiesFromEas, b1 as getItemVersionsFromEas, aV as getMetadataLatest, b0 as getModelSchemasFromEas, bv as getRevokeExecutor, bA as getSchemaNameFromId, b6 as getSeedsBySchemaName, b5 as getSeedsFromSchemaUids, bk as getUploadApiArweaveDataUrl, bm as getUploadApiArweaveStatusUrl, br as getUploadExecutor, bl as getUploadPipelineTransactionStatus, aU as getVersionData, ax as importJsonSchema, bo as isArweaveL1AnchoringComplete, bz as listSchemas, aW as loadAllSchemasFromDb, ac as modelSchemas, ad as modelUids, A as models, ba as normalizeFeedItemFields, bj as normalizeUploadApiBaseUrl, aP as parseAddressesPersistedPayload, bc as pickLatestPropertyAttestationsByRefAndSchema, C as properties, aX as propertyMachine, ah as propertyUids, ai as publishProcesses, bp as queryArweaveGatewayTransaction, az as readJsonImportFile, by as readSchema, b9 as resolveMediaRef, aj as schemas, bw as setAdditionalSyncAddresses, bs as setGetPublisherForNewSeeds, bu as setRevokeExecutor, a$ as setSchemaUidForModel, a_ as setSchemaUidForSchemaDefinition, bq as setUploadExecutor, aA as syncSchemaFromSource, aB as transformImportToSchemaFile, bh as updateSeedRevokedAt, ak as uploadProcesses, b7 as withExcludeRevokedFilter } from './index-BrD_NNaX.js';
|
|
4
|
+
export { getPropertySchema } from './property-C63Ddzap.js';
|
|
5
5
|
import { eq, desc, or, and, isNotNull, ne } from 'drizzle-orm';
|
|
6
|
-
export { S as Schema, a as deleteModelFromSchema, d as deletePropertyFromModel, r as renameModelProperty, s as schemaMachine, u as updateModelProperties } from './Schema-
|
|
7
|
-
export { ModelProperty } from './ModelProperty-
|
|
8
|
-
export { isItemOwned } from './ownership-
|
|
9
|
-
import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-
|
|
10
|
-
export { PublishValidationFailedError, resolvePublishPayloadValues, validateItemForPublish } from './getPublishPayload-
|
|
11
|
-
export { itemHasPublishUploadCandidates } from './getPublishUploads-
|
|
6
|
+
export { S as Schema, a as deleteModelFromSchema, d as deletePropertyFromModel, r as renameModelProperty, s as schemaMachine, u as updateModelProperties } from './Schema-CqqcEexA.js';
|
|
7
|
+
export { ModelProperty } from './ModelProperty-DWtv9fQr.js';
|
|
8
|
+
export { isItemOwned } from './ownership-BK6suksO.js';
|
|
9
|
+
import { g as getSegmentedItemProperties } from './getSegmentedItemProperties-Bz5B4DSA.js';
|
|
10
|
+
export { PublishValidationFailedError, resolvePublishPayloadValues, validateItemForPublish } from './getPublishPayload-DpYwi-rd.js';
|
|
11
|
+
export { itemHasPublishUploadCandidates } from './getPublishUploads-DS2dQ4Ho.js';
|
|
12
|
+
import { parseFragment, serialize } from 'parse5';
|
|
13
|
+
import 'pluralize';
|
|
12
14
|
import 'js-yaml';
|
|
13
15
|
import 'fs';
|
|
14
16
|
import 'xstate';
|
|
@@ -17,7 +19,6 @@ import 'nanoid';
|
|
|
17
19
|
import 'nanoid-dictionary';
|
|
18
20
|
import 'debug';
|
|
19
21
|
import 'ethers';
|
|
20
|
-
import 'pluralize';
|
|
21
22
|
import '@sinclair/typebox';
|
|
22
23
|
import 'drizzle-orm/casing';
|
|
23
24
|
import 'lodash-es';
|
|
@@ -25,16 +26,15 @@ import 'rxjs';
|
|
|
25
26
|
import 'eventemitter3';
|
|
26
27
|
import 'arweave';
|
|
27
28
|
import 'js-sha3';
|
|
28
|
-
import './SchemaValidationService-
|
|
29
|
+
import './SchemaValidationService-Cb-b4kpD.js';
|
|
29
30
|
import '@sinclair/typebox/value';
|
|
30
31
|
|
|
31
|
-
const isEmptyUid = (uid) => uid == null || uid === '' || uid === 'NULL';
|
|
32
32
|
/**
|
|
33
33
|
* Updates the version record with the attestation UID after a Version attestation is created.
|
|
34
34
|
* Targets the version without a uid yet (the one being published).
|
|
35
35
|
* Publisher is immutable once set: we never overwrite an existing publisher.
|
|
36
36
|
*/
|
|
37
|
-
const updateVersionUid = async ({ seedLocalId, versionUid, publisher, }) => {
|
|
37
|
+
const updateVersionUid = async ({ seedLocalId, versionUid, publisher, attestationCreatedAt, }) => {
|
|
38
38
|
if (!seedLocalId || !versionUid) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
@@ -46,7 +46,7 @@ const updateVersionUid = async ({ seedLocalId, versionUid, publisher, }) => {
|
|
|
46
46
|
.from(versions)
|
|
47
47
|
.where(eq(versions.seedLocalId, seedLocalId))
|
|
48
48
|
.orderBy(desc(versions.createdAt));
|
|
49
|
-
const toUpdate = rows.find((r) => r.localId &&
|
|
49
|
+
const toUpdate = rows.find((r) => r.localId && isPlaceholderUid(r.uid));
|
|
50
50
|
if (!toUpdate?.localId)
|
|
51
51
|
return;
|
|
52
52
|
let shouldSetPublisher = publisher != null && publisher !== '';
|
|
@@ -58,11 +58,78 @@ const updateVersionUid = async ({ seedLocalId, versionUid, publisher, }) => {
|
|
|
58
58
|
.set({
|
|
59
59
|
uid: versionUid,
|
|
60
60
|
...(shouldSetPublisher && { publisher }),
|
|
61
|
+
...(attestationCreatedAt != null && { attestationCreatedAt }),
|
|
61
62
|
updatedAt: Date.now(),
|
|
62
63
|
})
|
|
63
64
|
.where(eq(versions.localId, toUpdate.localId));
|
|
64
65
|
};
|
|
65
66
|
|
|
67
|
+
/**
|
|
68
|
+
* After property attestations succeed, write EAS UIDs onto the latest placeholder metadata row
|
|
69
|
+
* per schema (and optional property name) so getPublishPendingDiff stays aligned with on-chain state.
|
|
70
|
+
*/
|
|
71
|
+
async function applyPropertyAttestationUidsFromPublish(params) {
|
|
72
|
+
const { seedLocalId, attestationCreatedAtMs, pairs, versionUid } = params;
|
|
73
|
+
const appDb = BaseDb.getAppDb();
|
|
74
|
+
if (!appDb || !seedLocalId || pairs.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
const rows = await appDb.select().from(metadata).where(eq(metadata.seedLocalId, seedLocalId));
|
|
77
|
+
if (rows.length === 0)
|
|
78
|
+
return;
|
|
79
|
+
const working = rows.map((r) => ({ ...r }));
|
|
80
|
+
const validVersion = versionUid != null && versionUid !== '' && isValidEasAttestationUid(versionUid)
|
|
81
|
+
? versionUid
|
|
82
|
+
: undefined;
|
|
83
|
+
for (const pair of pairs) {
|
|
84
|
+
const att = pair.attestationUid?.trim();
|
|
85
|
+
if (!isValidEasAttestationUid(att))
|
|
86
|
+
continue;
|
|
87
|
+
const wantSchema = normalizeBytes32Hex(pair.schemaUid);
|
|
88
|
+
if (!wantSchema)
|
|
89
|
+
continue;
|
|
90
|
+
const candidates = working
|
|
91
|
+
.filter((r) => {
|
|
92
|
+
if (!r.schemaUid)
|
|
93
|
+
return false;
|
|
94
|
+
if (normalizeBytes32Hex(r.schemaUid) !== wantSchema)
|
|
95
|
+
return false;
|
|
96
|
+
if (pair.propertyName != null && pair.propertyName !== '') {
|
|
97
|
+
if (r.propertyName !== pair.propertyName)
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
})
|
|
102
|
+
.sort((a, b) => {
|
|
103
|
+
const ta = a.attestationCreatedAt ?? a.createdAt ?? 0;
|
|
104
|
+
const tb = b.attestationCreatedAt ?? b.createdAt ?? 0;
|
|
105
|
+
if (tb !== ta)
|
|
106
|
+
return tb - ta;
|
|
107
|
+
return String(b.localId ?? '').localeCompare(String(a.localId ?? ''));
|
|
108
|
+
});
|
|
109
|
+
const target = candidates.find((r) => isPlaceholderUid(r.uid));
|
|
110
|
+
if (!target?.localId)
|
|
111
|
+
continue;
|
|
112
|
+
await appDb
|
|
113
|
+
.update(metadata)
|
|
114
|
+
.set({
|
|
115
|
+
uid: att,
|
|
116
|
+
...(attestationCreatedAtMs != null && { attestationCreatedAt: attestationCreatedAtMs }),
|
|
117
|
+
...(validVersion && { versionUid: validVersion }),
|
|
118
|
+
updatedAt: Date.now(),
|
|
119
|
+
})
|
|
120
|
+
.where(eq(metadata.localId, target.localId));
|
|
121
|
+
const i = working.findIndex((r) => r.localId === target.localId);
|
|
122
|
+
if (i >= 0) {
|
|
123
|
+
working[i] = {
|
|
124
|
+
...working[i],
|
|
125
|
+
uid: att,
|
|
126
|
+
attestationCreatedAt: attestationCreatedAtMs ?? working[i].attestationCreatedAt,
|
|
127
|
+
...(validVersion && { versionUid: validVersion }),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
66
133
|
const getVersionsForSeedUid = async (seedUid) => {
|
|
67
134
|
if (!seedUid)
|
|
68
135
|
return [];
|
|
@@ -76,7 +143,7 @@ const getVersionsForSeedUid = async (seedUid) => {
|
|
|
76
143
|
.map((r) => ({ uid: r.uid }));
|
|
77
144
|
};
|
|
78
145
|
|
|
79
|
-
function resolveSeedIds(arg) {
|
|
146
|
+
function resolveSeedIds$1(arg) {
|
|
80
147
|
if (arg && typeof arg === 'object' && 'seedLocalId' in arg) {
|
|
81
148
|
const item = arg;
|
|
82
149
|
return {
|
|
@@ -87,12 +154,12 @@ function resolveSeedIds(arg) {
|
|
|
87
154
|
return arg;
|
|
88
155
|
}
|
|
89
156
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
157
|
+
* Per property: the **latest** metadata row (by `attestationCreatedAt` / `createdAt`) lacks a valid
|
|
158
|
+
* EAS attestation `uid` — local edit or missing post-publish UID backfill. **Not** equivalent to
|
|
159
|
+
* draft vs onchain for the whole seed; use `getSeedPublishState` for that.
|
|
93
160
|
*/
|
|
94
161
|
async function getPublishPendingDiff(arg) {
|
|
95
|
-
const { seedLocalId, seedUid } = resolveSeedIds(arg);
|
|
162
|
+
const { seedLocalId, seedUid } = resolveSeedIds$1(arg);
|
|
96
163
|
const appDb = BaseDb.getAppDb();
|
|
97
164
|
const empty = {
|
|
98
165
|
pendingProperties: [],
|
|
@@ -125,9 +192,9 @@ async function getPublishPendingDiff(arg) {
|
|
|
125
192
|
const latest = list[0];
|
|
126
193
|
if (!latest)
|
|
127
194
|
continue;
|
|
128
|
-
const hasUid =
|
|
195
|
+
const hasUid = isValidEasAttestationUid(latest.uid);
|
|
129
196
|
if (!hasUid) {
|
|
130
|
-
const prevWithUid = list.find((r) =>
|
|
197
|
+
const prevWithUid = list.find((r) => isValidEasAttestationUid(r.uid));
|
|
131
198
|
pendingProperties.push({
|
|
132
199
|
propertyName,
|
|
133
200
|
currentValue: latest.propertyValue ?? null,
|
|
@@ -140,21 +207,12 @@ async function getPublishPendingDiff(arg) {
|
|
|
140
207
|
let lastPublishedVersionUid = null;
|
|
141
208
|
let lastVersionPublishedAt = null;
|
|
142
209
|
if (seedLocalId) {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
.where(eq(versions.seedLocalId, seedLocalId))
|
|
150
|
-
.orderBy(desc(versions.createdAt))
|
|
151
|
-
.limit(1);
|
|
152
|
-
const vr = vRows[0];
|
|
153
|
-
if (vr?.uid && String(vr.uid).trim() !== '') {
|
|
154
|
-
lastPublishedVersionUid = vr.uid;
|
|
155
|
-
}
|
|
156
|
-
if (vr?.attestationCreatedAt != null) {
|
|
157
|
-
lastVersionPublishedAt = vr.attestationCreatedAt;
|
|
210
|
+
const published = await getLatestPublishedVersionRow(seedLocalId);
|
|
211
|
+
if (published) {
|
|
212
|
+
lastPublishedVersionUid = published.uid;
|
|
213
|
+
if (published.attestationCreatedAt != null) {
|
|
214
|
+
lastVersionPublishedAt = published.attestationCreatedAt;
|
|
215
|
+
}
|
|
158
216
|
}
|
|
159
217
|
}
|
|
160
218
|
return {
|
|
@@ -164,6 +222,87 @@ async function getPublishPendingDiff(arg) {
|
|
|
164
222
|
};
|
|
165
223
|
}
|
|
166
224
|
|
|
225
|
+
function resolveSeedIds(arg) {
|
|
226
|
+
if (arg && typeof arg === 'object' && 'seedLocalId' in arg) {
|
|
227
|
+
const item = arg;
|
|
228
|
+
return {
|
|
229
|
+
seedLocalId: item.seedLocalId,
|
|
230
|
+
seedUid: item.seedUid,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return arg;
|
|
234
|
+
}
|
|
235
|
+
function maxMs(a, b) {
|
|
236
|
+
const x = a ?? null;
|
|
237
|
+
const y = b ?? null;
|
|
238
|
+
if (x == null)
|
|
239
|
+
return y;
|
|
240
|
+
if (y == null)
|
|
241
|
+
return x;
|
|
242
|
+
return Math.max(x, y);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Whether the seed has **any** on-chain anchor in local SQLite: valid EAS UID on the seed row,
|
|
246
|
+
* on the newest **published** version row (`getLatestPublishedVersionRow`), or on **any** metadata row.
|
|
247
|
+
* Not the same as “no unpublished edits”; see `getPublishPendingDiff` for per-property head rows.
|
|
248
|
+
*/
|
|
249
|
+
async function getSeedPublishState(arg) {
|
|
250
|
+
const { seedLocalId, seedUid } = resolveSeedIds(arg);
|
|
251
|
+
const appDb = BaseDb.getAppDb();
|
|
252
|
+
const empty = {
|
|
253
|
+
status: 'draft',
|
|
254
|
+
seedAttestationUid: null,
|
|
255
|
+
versionAttestationUid: null,
|
|
256
|
+
explorerUid: null,
|
|
257
|
+
lastAttestedAtMs: null,
|
|
258
|
+
};
|
|
259
|
+
if (!appDb || (!seedLocalId && !seedUid)) {
|
|
260
|
+
return empty;
|
|
261
|
+
}
|
|
262
|
+
const seedWhere = seedLocalId && seedUid
|
|
263
|
+
? or(eq(seeds.localId, seedLocalId), eq(seeds.uid, seedUid))
|
|
264
|
+
: seedLocalId
|
|
265
|
+
? eq(seeds.localId, seedLocalId)
|
|
266
|
+
: eq(seeds.uid, seedUid);
|
|
267
|
+
const seedRows = await appDb.select().from(seeds).where(seedWhere).limit(1);
|
|
268
|
+
const seedRow = seedRows[0];
|
|
269
|
+
const seedAttestationUid = seedRow?.uid && isValidEasAttestationUid(seedRow.uid) ? seedRow.uid : null;
|
|
270
|
+
let lastAttestedAtMs = seedRow?.attestationCreatedAt ?? null;
|
|
271
|
+
const resolvedSeedLocalId = seedRow?.localId ?? seedLocalId;
|
|
272
|
+
let versionAttestationUid = null;
|
|
273
|
+
if (resolvedSeedLocalId) {
|
|
274
|
+
const v = await getLatestPublishedVersionRow(resolvedSeedLocalId);
|
|
275
|
+
if (v?.uid) {
|
|
276
|
+
versionAttestationUid = v.uid;
|
|
277
|
+
lastAttestedAtMs = maxMs(lastAttestedAtMs, v.attestationCreatedAt ?? undefined);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const metaWhere = seedLocalId && seedUid
|
|
281
|
+
? or(eq(metadata.seedLocalId, seedLocalId), eq(metadata.seedUid, seedUid))
|
|
282
|
+
: seedLocalId
|
|
283
|
+
? eq(metadata.seedLocalId, seedLocalId)
|
|
284
|
+
: eq(metadata.seedUid, seedUid);
|
|
285
|
+
const metaRows = await appDb.select().from(metadata).where(metaWhere);
|
|
286
|
+
let metadataExplorerUid = null;
|
|
287
|
+
for (const row of metaRows) {
|
|
288
|
+
if (!isValidEasAttestationUid(row.uid))
|
|
289
|
+
continue;
|
|
290
|
+
if (!metadataExplorerUid)
|
|
291
|
+
metadataExplorerUid = row.uid;
|
|
292
|
+
const t = row.attestationCreatedAt ?? row.createdAt;
|
|
293
|
+
lastAttestedAtMs = maxMs(lastAttestedAtMs, t ?? undefined);
|
|
294
|
+
}
|
|
295
|
+
const hasOnchain = !!(seedAttestationUid || versionAttestationUid || metadataExplorerUid);
|
|
296
|
+
const explorerUid = seedAttestationUid ?? versionAttestationUid ?? metadataExplorerUid;
|
|
297
|
+
return {
|
|
298
|
+
status: hasOnchain ? 'onchain' : 'draft',
|
|
299
|
+
seedAttestationUid,
|
|
300
|
+
versionAttestationUid,
|
|
301
|
+
explorerUid,
|
|
302
|
+
lastAttestedAtMs,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
167
306
|
/**
|
|
168
307
|
* Returns attestation UIDs (metadata.uid) for all metadata records belonging to a seed.
|
|
169
308
|
* Used when revoking attestations - metadata attestations must be revoked.
|
|
@@ -175,7 +314,7 @@ const getMetadataAttestationUidsForSeedUid = async (seedUid) => {
|
|
|
175
314
|
const rows = await appDb
|
|
176
315
|
.select({ uid: metadata.uid, schemaUid: metadata.schemaUid })
|
|
177
316
|
.from(metadata)
|
|
178
|
-
.where(and(eq(metadata.seedUid, seedUid), isNotNull(metadata.uid), ne(metadata.uid, ''), ne(metadata.uid, '0x' + '0'.repeat(64))));
|
|
317
|
+
.where(and(eq(metadata.seedUid, seedUid), isNotNull(metadata.uid), ne(metadata.uid, ''), ne(metadata.uid, 'NULL'), ne(metadata.uid, '0x' + '0'.repeat(64))));
|
|
179
318
|
return rows
|
|
180
319
|
.filter((r) => r.uid != null && r.schemaUid != null)
|
|
181
320
|
.map((r) => ({ uid: r.uid, schemaUid: r.schemaUid }));
|
|
@@ -282,7 +421,7 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
282
421
|
visited.add(seedLocalId);
|
|
283
422
|
const result = [];
|
|
284
423
|
const { itemRelationProperties, itemImageProperties, itemListProperties } = await getSegmentedItemProperties(item);
|
|
285
|
-
const getItemMod = await import('./getItem-
|
|
424
|
+
const getItemMod = await import('./getItem-VI3QqdZH.js');
|
|
286
425
|
const { getItem } = getItemMod;
|
|
287
426
|
const processRelationOrImage = async (prop) => {
|
|
288
427
|
const snapshot = prop.getService().getSnapshot();
|
|
@@ -303,8 +442,8 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
303
442
|
if (!value && prop.propertyName && isStorageSeed) {
|
|
304
443
|
const ctx = context;
|
|
305
444
|
if (ctx.seedLocalId || ctx.seedUid) {
|
|
306
|
-
const _mod_0 = await import('./index-
|
|
307
|
-
const _ns_0 = _mod_0.
|
|
445
|
+
const _mod_0 = await import('./index-BrD_NNaX.js');
|
|
446
|
+
const _ns_0 = _mod_0.bP;
|
|
308
447
|
const { getPropertyData } = _ns_0;
|
|
309
448
|
const meta = await getPropertyData({
|
|
310
449
|
propertyName: prop.propertyName,
|
|
@@ -362,5 +501,353 @@ async function getRelatedItemsForPublish(item, visited = new Set()) {
|
|
|
362
501
|
return result;
|
|
363
502
|
}
|
|
364
503
|
|
|
365
|
-
|
|
504
|
+
const HTML_EMBEDDED_MAX_IMAGES_PER_DOC = 50;
|
|
505
|
+
const HTML_EMBEDDED_MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
506
|
+
const HTML_EMBEDDED_MAX_TOTAL_BYTES = 25 * 1024 * 1024;
|
|
507
|
+
const DATA_URI_IMAGE = /^data:(image\/[a-zA-Z0-9.+-]+);base64,([\s\S]*)$/i;
|
|
508
|
+
const MIME_NORMALIZE = {
|
|
509
|
+
'image/jpg': 'image/jpeg',
|
|
510
|
+
};
|
|
511
|
+
function normalizeMime(m) {
|
|
512
|
+
const lower = m.toLowerCase().trim();
|
|
513
|
+
return MIME_NORMALIZE[lower] ?? lower;
|
|
514
|
+
}
|
|
515
|
+
const ALLOWED_MIMES = new Set([
|
|
516
|
+
'image/png',
|
|
517
|
+
'image/jpeg',
|
|
518
|
+
'image/webp',
|
|
519
|
+
'image/gif',
|
|
520
|
+
'image/svg+xml',
|
|
521
|
+
]);
|
|
522
|
+
class HtmlEmbeddedDataUriLimitError extends Error {
|
|
523
|
+
constructor(message) {
|
|
524
|
+
super(message);
|
|
525
|
+
this.name = 'HtmlEmbeddedDataUriLimitError';
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function resolveEffectiveHtmlEmbeddedDataUriPolicy(propertyDef, publishLevel) {
|
|
529
|
+
const fromProp = propertyDef?.htmlEmbeddedDataUriPolicy;
|
|
530
|
+
if (fromProp === 'materialize' || fromProp === 'preserve')
|
|
531
|
+
return fromProp;
|
|
532
|
+
if (publishLevel === 'materialize' || publishLevel === 'preserve')
|
|
533
|
+
return publishLevel;
|
|
534
|
+
return 'materialize';
|
|
535
|
+
}
|
|
536
|
+
function getAttr(node, name) {
|
|
537
|
+
const a = node.attrs?.find((x) => x.name === name);
|
|
538
|
+
return a?.value;
|
|
539
|
+
}
|
|
540
|
+
function setAttr(node, name, value) {
|
|
541
|
+
if (!node.attrs)
|
|
542
|
+
node.attrs = [];
|
|
543
|
+
const i = node.attrs.findIndex((x) => x.name === name);
|
|
544
|
+
if (i >= 0)
|
|
545
|
+
node.attrs[i].value = value;
|
|
546
|
+
else
|
|
547
|
+
node.attrs.push({ name, value });
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Walk fragment tree; collect unique data:image base64 URIs with limits.
|
|
551
|
+
*/
|
|
552
|
+
async function extractDataUriImagesFromHtml(html) {
|
|
553
|
+
const fragment = parseFragment(html);
|
|
554
|
+
const found = [];
|
|
555
|
+
const seenUris = new Set();
|
|
556
|
+
let totalBytes = 0;
|
|
557
|
+
const walk = async (node) => {
|
|
558
|
+
if (node.nodeName === '#text' || node.nodeName === '#comment')
|
|
559
|
+
return;
|
|
560
|
+
const el = node;
|
|
561
|
+
if (el.tagName === 'img') {
|
|
562
|
+
const src = getAttr(el, 'src')?.trim();
|
|
563
|
+
if (src && src.startsWith('data:image/')) {
|
|
564
|
+
const m = DATA_URI_IMAGE.exec(src);
|
|
565
|
+
if (m) {
|
|
566
|
+
const mimeRaw = normalizeMime(m[1]);
|
|
567
|
+
if (!ALLOWED_MIMES.has(mimeRaw)) {
|
|
568
|
+
throw new HtmlEmbeddedDataUriLimitError(`Unsupported embedded image type: ${mimeRaw}. Allowed: ${[...ALLOWED_MIMES].join(', ')}`);
|
|
569
|
+
}
|
|
570
|
+
let binary;
|
|
571
|
+
try {
|
|
572
|
+
const b64 = m[2].replace(/\s/g, '');
|
|
573
|
+
binary = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
574
|
+
}
|
|
575
|
+
catch {
|
|
576
|
+
throw new HtmlEmbeddedDataUriLimitError('Invalid base64 in embedded image data URI');
|
|
577
|
+
}
|
|
578
|
+
const byteLength = binary.byteLength;
|
|
579
|
+
if (byteLength > HTML_EMBEDDED_MAX_IMAGE_BYTES) {
|
|
580
|
+
throw new HtmlEmbeddedDataUriLimitError(`Embedded image exceeds max size (${HTML_EMBEDDED_MAX_IMAGE_BYTES} bytes)`);
|
|
581
|
+
}
|
|
582
|
+
totalBytes += byteLength;
|
|
583
|
+
if (totalBytes > HTML_EMBEDDED_MAX_TOTAL_BYTES) {
|
|
584
|
+
throw new HtmlEmbeddedDataUriLimitError(`Total embedded image size exceeds max (${HTML_EMBEDDED_MAX_TOTAL_BYTES} bytes)`);
|
|
585
|
+
}
|
|
586
|
+
if (!seenUris.has(src)) {
|
|
587
|
+
if (seenUris.size >= HTML_EMBEDDED_MAX_IMAGES_PER_DOC) {
|
|
588
|
+
throw new HtmlEmbeddedDataUriLimitError(`Too many distinct embedded images (max ${HTML_EMBEDDED_MAX_IMAGES_PER_DOC})`);
|
|
589
|
+
}
|
|
590
|
+
seenUris.add(src);
|
|
591
|
+
const stableKey = await getContentHash(binary);
|
|
592
|
+
found.push({ dataUri: src, stableKey, byteLength, mimeType: mimeRaw });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
const parent = el;
|
|
598
|
+
if (parent.childNodes) {
|
|
599
|
+
for (const c of parent.childNodes)
|
|
600
|
+
await walk(c);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
for (const c of fragment.childNodes)
|
|
604
|
+
await walk(c);
|
|
605
|
+
return found;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Replace `data:image/...` src values with Arweave URLs using upload results keyed by image seed local id.
|
|
609
|
+
*/
|
|
610
|
+
function replaceDataUrisInParsedHtml(html, replacements) {
|
|
611
|
+
if (replacements.size === 0)
|
|
612
|
+
return html;
|
|
613
|
+
const fragment = parseFragment(html);
|
|
614
|
+
const walk = (node) => {
|
|
615
|
+
if (node.nodeName === '#text' || node.nodeName === '#comment')
|
|
616
|
+
return;
|
|
617
|
+
const el = node;
|
|
618
|
+
if (el.tagName === 'img') {
|
|
619
|
+
const src = getAttr(el, 'src')?.trim();
|
|
620
|
+
if (src && replacements.has(src)) {
|
|
621
|
+
setAttr(el, 'src', replacements.get(src));
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const parent = el;
|
|
625
|
+
if (parent.childNodes) {
|
|
626
|
+
for (const c of parent.childNodes)
|
|
627
|
+
walk(c);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
for (const c of fragment.childNodes)
|
|
631
|
+
walk(c);
|
|
632
|
+
return serialize(fragment);
|
|
633
|
+
}
|
|
634
|
+
async function deleteCoPublishRowsForParent(appDb, parentSeedLocalId) {
|
|
635
|
+
if (!appDb)
|
|
636
|
+
return;
|
|
637
|
+
await appDb.delete(htmlEmbeddedImageCoPublish).where(eq(htmlEmbeddedImageCoPublish.parentSeedLocalId, parentSeedLocalId));
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Create an Image item and persist a data URI into its storageTransactionId (same path as user paste).
|
|
641
|
+
*/
|
|
642
|
+
async function createImageItemFromDataUri(dataUri) {
|
|
643
|
+
const imageItem = await Item.create({
|
|
644
|
+
modelName: 'Image',
|
|
645
|
+
});
|
|
646
|
+
await waitForEntityIdle(imageItem, { timeout: 60000 });
|
|
647
|
+
// #region agent log
|
|
648
|
+
fetch('http://127.0.0.1:7754/ingest/2810478a-7cf0-49a8-bc23-760b81417972', {
|
|
649
|
+
method: 'POST',
|
|
650
|
+
headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '5954ea' },
|
|
651
|
+
body: JSON.stringify({
|
|
652
|
+
sessionId: '5954ea',
|
|
653
|
+
location: 'htmlEmbeddedDataUriPublish.ts:createImageItemFromDataUri',
|
|
654
|
+
message: 'after waitForEntityIdle',
|
|
655
|
+
data: {
|
|
656
|
+
seedLocalId: imageItem.seedLocalId,
|
|
657
|
+
allPropertyKeys: Object.keys(imageItem.allProperties),
|
|
658
|
+
hasStorageTransactionId: !!imageItem.allProperties['storageTransactionId'],
|
|
659
|
+
hasStorageTransactionWrongKey: !!imageItem.allProperties['storageTransaction'],
|
|
660
|
+
},
|
|
661
|
+
timestamp: Date.now(),
|
|
662
|
+
runId: 'post-fix',
|
|
663
|
+
hypothesisId: 'A',
|
|
664
|
+
}),
|
|
665
|
+
}).catch(() => { });
|
|
666
|
+
// #endregion
|
|
667
|
+
const st = imageItem.internalProperties['storageTransactionId'] ??
|
|
668
|
+
imageItem.allProperties['storageTransactionId'];
|
|
669
|
+
if (!st) {
|
|
670
|
+
throw new Error('Image item missing storageTransactionId property');
|
|
671
|
+
}
|
|
672
|
+
st.value = dataUri;
|
|
673
|
+
await st.save();
|
|
674
|
+
await waitForEntityIdle(imageItem, { timeout: 60000 });
|
|
675
|
+
return { seedLocalId: imageItem.seedLocalId };
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Scan Html storage properties, materialize embedded images as Image items, insert co-publish rows.
|
|
679
|
+
* Call before phase-1 Arweave tx build. Does not rewrite Html files yet.
|
|
680
|
+
*/
|
|
681
|
+
async function prepareHtmlEmbeddedImagesForPublish(item, publishPolicy) {
|
|
682
|
+
const appDb = BaseDb.getAppDb();
|
|
683
|
+
if (!appDb) {
|
|
684
|
+
return { deferredHtmlSeedLocalIds: [] };
|
|
685
|
+
}
|
|
686
|
+
await deleteCoPublishRowsForParent(appDb, item.seedLocalId);
|
|
687
|
+
const deferred = new Set();
|
|
688
|
+
for (const p of item.properties) {
|
|
689
|
+
const def = p.propertyDef;
|
|
690
|
+
if (!def || normalizeDataTypeLocal(def.dataType) !== ModelPropertyDataTypes.Html)
|
|
691
|
+
continue;
|
|
692
|
+
const policy = resolveEffectiveHtmlEmbeddedDataUriPolicy(def, publishPolicy);
|
|
693
|
+
if (policy !== 'materialize')
|
|
694
|
+
continue;
|
|
695
|
+
const snap = p.getService().getSnapshot();
|
|
696
|
+
const ctx = 'context' in snap ? snap.context : null;
|
|
697
|
+
const htmlSeedLocalId = typeof ctx?.propertyValue === 'string' ? ctx.propertyValue : '';
|
|
698
|
+
const refResolved = ctx?.refResolvedValue;
|
|
699
|
+
if (!htmlSeedLocalId?.trim() || !refResolved)
|
|
700
|
+
continue;
|
|
701
|
+
const filePath = `${BaseFileManager.getFilesPath('html')}/${refResolved}`;
|
|
702
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
703
|
+
if (!exists)
|
|
704
|
+
continue;
|
|
705
|
+
let html;
|
|
706
|
+
try {
|
|
707
|
+
html = await BaseFileManager.readFileAsString(filePath);
|
|
708
|
+
}
|
|
709
|
+
catch {
|
|
710
|
+
const buf = await BaseFileManager.readFileAsBuffer(filePath);
|
|
711
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(buf)) {
|
|
712
|
+
html = buf.toString('utf-8');
|
|
713
|
+
}
|
|
714
|
+
else if (typeof Blob !== 'undefined' && buf instanceof Blob) {
|
|
715
|
+
html = await buf.text();
|
|
716
|
+
}
|
|
717
|
+
else if (buf instanceof ArrayBuffer) {
|
|
718
|
+
html = new TextDecoder('utf-8', { fatal: false }).decode(buf);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
const v = buf;
|
|
722
|
+
html = new TextDecoder('utf-8', { fatal: false }).decode(new Uint8Array(v.buffer, v.byteOffset, v.byteLength));
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
let extracted;
|
|
726
|
+
try {
|
|
727
|
+
extracted = await extractDataUriImagesFromHtml(html);
|
|
728
|
+
}
|
|
729
|
+
catch (e) {
|
|
730
|
+
if (e instanceof HtmlEmbeddedDataUriLimitError)
|
|
731
|
+
throw e;
|
|
732
|
+
throw e;
|
|
733
|
+
}
|
|
734
|
+
if (extracted.length === 0)
|
|
735
|
+
continue;
|
|
736
|
+
deferred.add(htmlSeedLocalId.trim());
|
|
737
|
+
for (const ent of extracted) {
|
|
738
|
+
const { seedLocalId: imageSeedLocalId } = await createImageItemFromDataUri(ent.dataUri);
|
|
739
|
+
const now = Date.now();
|
|
740
|
+
await appDb.insert(htmlEmbeddedImageCoPublish).values({
|
|
741
|
+
parentSeedLocalId: item.seedLocalId,
|
|
742
|
+
htmlSeedLocalId: htmlSeedLocalId.trim(),
|
|
743
|
+
imageSeedLocalId,
|
|
744
|
+
stableKey: ent.stableKey,
|
|
745
|
+
createdAt: now,
|
|
746
|
+
}).onConflictDoNothing();
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return { deferredHtmlSeedLocalIds: [...deferred] };
|
|
750
|
+
}
|
|
751
|
+
function normalizeDataTypeLocal(dt) {
|
|
752
|
+
if (!dt)
|
|
753
|
+
return '';
|
|
754
|
+
return dt.charAt(0).toUpperCase() + dt.slice(1).toLowerCase();
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* After phase-1 uploads, rewrite Html files on disk: data URI → Arweave gateway URL.
|
|
758
|
+
*/
|
|
759
|
+
async function rewriteHtmlEmbeddedImagesOnDisk(parentSeedLocalId, uploadedTransactions) {
|
|
760
|
+
const appDb = BaseDb.getAppDb();
|
|
761
|
+
if (!appDb)
|
|
762
|
+
return;
|
|
763
|
+
const rows = await appDb
|
|
764
|
+
.select()
|
|
765
|
+
.from(htmlEmbeddedImageCoPublish)
|
|
766
|
+
.where(eq(htmlEmbeddedImageCoPublish.parentSeedLocalId, parentSeedLocalId));
|
|
767
|
+
if (rows.length === 0)
|
|
768
|
+
return;
|
|
769
|
+
const txByImageSeed = new Map();
|
|
770
|
+
for (const u of uploadedTransactions) {
|
|
771
|
+
if (u.seedLocalId && u.txId) {
|
|
772
|
+
txByImageSeed.set(u.seedLocalId.trim(), u.txId.trim());
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const htmlSeedIds = new Set(rows.map((r) => String(r.htmlSeedLocalId).trim()));
|
|
776
|
+
const parentItem = await Item.find({ seedLocalId: parentSeedLocalId });
|
|
777
|
+
const refByHtmlSeed = new Map();
|
|
778
|
+
if (parentItem) {
|
|
779
|
+
for (const p of parentItem.properties) {
|
|
780
|
+
const def = p.propertyDef;
|
|
781
|
+
if (!def || normalizeDataTypeLocal(def.dataType) !== ModelPropertyDataTypes.Html)
|
|
782
|
+
continue;
|
|
783
|
+
const snap = p.getService().getSnapshot();
|
|
784
|
+
const ctx = 'context' in snap ? snap.context : null;
|
|
785
|
+
const pv = typeof ctx?.propertyValue === 'string' ? ctx.propertyValue.trim() : '';
|
|
786
|
+
const refResolved = ctx?.refResolvedValue;
|
|
787
|
+
if (pv && refResolved)
|
|
788
|
+
refByHtmlSeed.set(pv, refResolved);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
for (const htmlSeedLocalId of htmlSeedIds) {
|
|
792
|
+
const refResolved = refByHtmlSeed.get(String(htmlSeedLocalId));
|
|
793
|
+
if (!refResolved)
|
|
794
|
+
continue;
|
|
795
|
+
const filePath = `${BaseFileManager.getFilesPath('html')}/${refResolved}`;
|
|
796
|
+
if (!(await BaseFileManager.pathExists(filePath)))
|
|
797
|
+
continue;
|
|
798
|
+
const html = await BaseFileManager.readFileAsString(filePath);
|
|
799
|
+
const replacements = new Map();
|
|
800
|
+
for (const r of rows) {
|
|
801
|
+
if (String(r.htmlSeedLocalId).trim() !== htmlSeedLocalId)
|
|
802
|
+
continue;
|
|
803
|
+
const txId = txByImageSeed.get(r.imageSeedLocalId.trim());
|
|
804
|
+
if (!txId)
|
|
805
|
+
continue;
|
|
806
|
+
const dataUri = await findDataUriForStableKey(html, r.stableKey);
|
|
807
|
+
if (dataUri)
|
|
808
|
+
replacements.set(dataUri, getArweaveUrlForTransaction(txId));
|
|
809
|
+
}
|
|
810
|
+
if (replacements.size === 0)
|
|
811
|
+
continue;
|
|
812
|
+
const newHtml = replaceDataUrisInParsedHtml(html, replacements);
|
|
813
|
+
try {
|
|
814
|
+
await BaseFileManager.saveFile(filePath, newHtml);
|
|
815
|
+
}
|
|
816
|
+
catch {
|
|
817
|
+
const fs = await BaseFileManager.getFs();
|
|
818
|
+
fs.writeFileSync(filePath, newHtml);
|
|
819
|
+
}
|
|
820
|
+
if (parentItem) {
|
|
821
|
+
for (const p of parentItem.properties) {
|
|
822
|
+
const snap = p.getService().getSnapshot();
|
|
823
|
+
const ctx = 'context' in snap ? snap.context : null;
|
|
824
|
+
const pv = typeof ctx?.propertyValue === 'string' ? ctx.propertyValue.trim() : '';
|
|
825
|
+
if (pv === htmlSeedLocalId) {
|
|
826
|
+
p.getService().send({
|
|
827
|
+
type: 'updateContext',
|
|
828
|
+
renderValue: newHtml,
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
async function findDataUriForStableKey(html, stableKey) {
|
|
836
|
+
const entries = await extractDataUriImagesFromHtml(html);
|
|
837
|
+
const hit = entries.find((e) => e.stableKey === stableKey);
|
|
838
|
+
return hit?.dataUri;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Remove co-publish rows after a successful publish for this parent seed.
|
|
842
|
+
*/
|
|
843
|
+
async function clearHtmlEmbeddedImageCoPublishRows(parentSeedLocalId) {
|
|
844
|
+
const appDb = BaseDb.getAppDb();
|
|
845
|
+
if (!appDb || !parentSeedLocalId)
|
|
846
|
+
return;
|
|
847
|
+
await appDb
|
|
848
|
+
.delete(htmlEmbeddedImageCoPublish)
|
|
849
|
+
.where(eq(htmlEmbeddedImageCoPublish.parentSeedLocalId, parentSeedLocalId.trim()));
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
export { BaseDb, BaseFileManager, BaseFileManager as FileManager, HTML_EMBEDDED_MAX_IMAGES_PER_DOC, HTML_EMBEDDED_MAX_IMAGE_BYTES, HTML_EMBEDDED_MAX_TOTAL_BYTES, HtmlEmbeddedDataUriLimitError, Item, ModelPropertyDataTypes, applyArweaveL1TransactionIdLocal, applyPropertyAttestationUidsFromPublish, clearHtmlEmbeddedImageCoPublishRows, extractDataUriImagesFromHtml, getArweaveUrlForTransaction, getAttesterForSeed, getMetadataAttestationUidsForSeedUid, getPublishPendingDiff, getRelatedItemsForPublish, getSeedPublishState, getSegmentedItemProperties, getVersionsForSeedUid, htmlEmbeddedImageCoPublish, isPlaceholderUid, isValidEasAttestationUid, metadata, normalizeBytes32Hex, prepareHtmlEmbeddedImagesForPublish, replaceDataUrisInParsedHtml, resolveEffectiveHtmlEmbeddedDataUriPolicy, rewriteHtmlEmbeddedImagesOnDisk, seeds, updateVersionUid, versions, waitForEntityIdle };
|
|
366
853
|
//# sourceMappingURL=main.js.map
|