@seedprotocol/sdk 0.5.1 → 0.5.3
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/{BasePathResolver-BDgc7c4T.js → BasePathResolver-DWY_hb8w.js} +2 -2
- package/dist/{BasePathResolver-BDgc7c4T.js.map → BasePathResolver-DWY_hb8w.js.map} +1 -1
- package/dist/{ModelProperty-D-ysg8zA.js → ModelProperty-DGJf78CS.js} +22 -21
- package/dist/ModelProperty-DGJf78CS.js.map +1 -0
- package/dist/{Schema-CyCftnKI.js → Schema-Drmce3q-.js} +39 -39
- package/dist/{Schema-CyCftnKI.js.map → Schema-Drmce3q-.js.map} +1 -1
- package/dist/{SchemaValidationService-POM6jHbJ.js → SchemaValidationService-a_sfnpDV.js} +6 -5
- package/dist/{SchemaValidationService-POM6jHbJ.js.map → SchemaValidationService-a_sfnpDV.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-DzZw57iJ.js → backfillMetadataPropertyIds-CZcOi-cK.js} +3 -3
- package/dist/{backfillMetadataPropertyIds-DzZw57iJ.js.map → backfillMetadataPropertyIds-CZcOi-cK.js.map} +1 -1
- package/dist/cjs/{ModelProperty-CmuGJvyi.js → ModelProperty-BA26rMV8.js} +18 -18
- package/dist/cjs/{ModelProperty-CmuGJvyi.js.map → ModelProperty-BA26rMV8.js.map} +1 -1
- package/dist/cjs/{Schema-gpFnZMhB.js → Schema-Hgwq3L34.js} +21 -21
- package/dist/cjs/{Schema-gpFnZMhB.js.map → Schema-Hgwq3L34.js.map} +1 -1
- package/dist/cjs/{SchemaValidationService-E3xTSRai.js → SchemaValidationService-DVmOGZao.js} +3 -3
- package/dist/cjs/{SchemaValidationService-E3xTSRai.js.map → SchemaValidationService-DVmOGZao.js.map} +1 -1
- package/dist/cjs/{backfillMetadataPropertyIds-_bivrvRs.js → backfillMetadataPropertyIds-BWJI4eCj.js} +3 -3
- package/dist/cjs/{backfillMetadataPropertyIds-_bivrvRs.js.map → backfillMetadataPropertyIds-BWJI4eCj.js.map} +1 -1
- package/dist/cjs/{eas-BwDKJmlb.js → eas-BJ8FtbU9.js} +4 -4
- package/dist/cjs/{eas-BwDKJmlb.js.map → eas-BJ8FtbU9.js.map} +1 -1
- package/dist/cjs/{getItem-MShQw3sz.js → getItem-DdBKeEEU.js} +3 -3
- package/dist/cjs/{getItem-MShQw3sz.js.map → getItem-DdBKeEEU.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-C1nOOXp_.js → getPublishPayload-DSBLjMKl.js} +12 -12
- package/dist/cjs/{getPublishPayload-C1nOOXp_.js.map → getPublishPayload-DSBLjMKl.js.map} +1 -1
- package/dist/cjs/{getPublishUploads-BjgxgrKD.js → getPublishUploads-DMKnK2_R.js} +5 -5
- package/dist/cjs/{getPublishUploads-BjgxgrKD.js.map → getPublishUploads-DMKnK2_R.js.map} +1 -1
- package/dist/cjs/{getSegmentedItemProperties-Cuw7wcxb.js → getSegmentedItemProperties-D0ZzTmvi.js} +3 -3
- package/dist/cjs/{getSegmentedItemProperties-Cuw7wcxb.js.map → getSegmentedItemProperties-D0ZzTmvi.js.map} +1 -1
- package/dist/cjs/{index-vk2DeF2D.js → index-BD1b6zAi.js} +935 -60
- package/dist/cjs/index-BD1b6zAi.js.map +1 -0
- package/dist/cjs/{index-9Z2FOvLD.js → index-DQggpLqI.js} +4 -4
- package/dist/cjs/index-DQggpLqI.js.map +1 -0
- package/dist/cjs/index.browser-BSf8HpnU.js.map +1 -1
- package/dist/cjs/{property-D3Ww2_Qh.js → property-D4IB0zBz.js} +5 -5
- package/dist/cjs/{property-D3Ww2_Qh.js.map → property-D4IB0zBz.js.map} +1 -1
- package/dist/cjs/{syncDbWithEas-Dht3_7UD.js → syncDbWithEas-BYvFJc7N.js} +46 -49
- package/dist/cjs/syncDbWithEas-BYvFJc7N.js.map +1 -0
- package/dist/{configurePlatform-R5neRbQ9.js → configurePlatform-CXQCT7N8.js} +4 -3
- package/dist/{configurePlatform-R5neRbQ9.js.map → configurePlatform-CXQCT7N8.js.map} +1 -1
- package/dist/{constants-B5S5JPDK.js → constants-B7aNfB_1.js} +14 -19
- package/dist/constants-B7aNfB_1.js.map +1 -0
- package/dist/constants-DMHTYMgJ.js.map +1 -1
- package/dist/{db-Cvh84NY7.js → db-Bad8QKfZ.js} +18 -18
- package/dist/{db-Cvh84NY7.js.map → db-Bad8QKfZ.js.map} +1 -1
- package/dist/{eas-D9b7z2Wn.js → eas-BB9hVW68.js} +7 -6
- package/dist/eas-BB9hVW68.js.map +1 -0
- package/dist/{getItem-B81V3m4S.js → getItem-Cina46nb.js} +6 -5
- package/dist/{getItem-B81V3m4S.js.map → getItem-Cina46nb.js.map} +1 -1
- package/dist/{getPublishPayload-CNYsn8-6.js → getPublishPayload-BEO52UOv.js} +17 -16
- package/dist/getPublishPayload-BEO52UOv.js.map +1 -0
- package/dist/{getPublishUploads-D9rPHkB7.js → getPublishUploads-CJjfqJi9.js} +8 -7
- package/dist/{getPublishUploads-D9rPHkB7.js.map → getPublishUploads-CJjfqJi9.js.map} +1 -1
- package/dist/{getSegmentedItemProperties-Bg3_b-b1.js → getSegmentedItemProperties-CbzFDgFr.js} +5 -5
- package/dist/{getSegmentedItemProperties-Bg3_b-b1.js.map → getSegmentedItemProperties-CbzFDgFr.js.map} +1 -1
- package/dist/{index--F3Wolt5.js → index-B4In0GEO.js} +863 -67
- package/dist/index-B4In0GEO.js.map +1 -0
- package/dist/index-DNOCl06b.js +28 -0
- package/dist/index-DNOCl06b.js.map +1 -0
- package/dist/{index-QMrBK-L3.js → index-DrEkRiuK.js} +2 -2
- package/dist/index-DrEkRiuK.js.map +1 -0
- package/dist/{index.node-Bow8kHew.js → index.node-CnP9s4cV.js} +4 -4
- package/dist/{index.node-Bow8kHew.js.map → index.node-CnP9s4cV.js.map} +1 -1
- package/dist/main.cjs +3 -6
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +21 -21
- package/dist/node.js +33 -12
- package/dist/node.js.map +1 -1
- package/dist/platform.browser.js +18 -5
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.node.js +3 -3
- package/dist/{property-BdyDfcSc.js → property-DIN1zQ_c.js} +9 -8
- package/dist/property-DIN1zQ_c.js.map +1 -0
- package/dist/src/Item/Item.d.ts +5 -0
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/Item/service/actors/saveDataToDb.d.ts.map +1 -1
- package/dist/src/Item/service/itemMachineSingle.d.ts +2 -2
- package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +2 -2
- package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
- package/dist/src/Model/service/modelMachine.d.ts +10 -18
- package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +5 -13
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
- package/dist/src/Schema/service/addModelsMachine.d.ts +8 -8
- package/dist/src/Schema/service/addModelsMachine.d.ts.map +1 -1
- package/dist/src/Schema/service/schemaMachine.d.ts +22 -30
- package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
- package/dist/src/browser/helpers/ArweaveClient.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +16 -6
- 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/actors/saveConfig.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts +2 -2
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/client/events.d.ts +7 -0
- package/dist/src/client/events.d.ts.map +1 -1
- package/dist/src/db/read/getItemData.d.ts +8 -0
- package/dist/src/db/read/getItemData.d.ts.map +1 -1
- package/dist/src/db/write/removeLocalCopiesForAddresses.d.ts +20 -0
- package/dist/src/db/write/removeLocalCopiesForAddresses.d.ts.map +1 -0
- package/dist/src/events/item/easSyncManager.d.ts +2 -2
- package/dist/src/events/item/easSyncManager.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/helpers/file/download/index.d.ts +2 -2
- package/dist/src/helpers/file/download/index.d.ts.map +1 -1
- package/dist/src/helpers/file/fetchAll/index.d.ts +2 -2
- package/dist/src/helpers/file/fetchAll/index.d.ts.map +1 -1
- package/dist/src/helpers/gateway/resolveSeedGatewayEndpoints.d.ts +1 -1
- package/dist/src/helpers/gateway/resolveSeedGatewayEndpoints.d.ts.map +1 -1
- package/dist/src/helpers/index.d.ts +1 -5
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/mediaRef.d.ts +3 -0
- package/dist/src/helpers/mediaRef.d.ts.map +1 -1
- package/dist/src/helpers/ownership.d.ts +7 -0
- package/dist/src/helpers/ownership.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/node/webpack/index.d.ts +4 -1
- package/dist/src/node/webpack/index.d.ts.map +1 -1
- package/dist/src/query/createLocalQueryDataSource.d.ts +6 -0
- package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -0
- package/dist/src/query/index.d.ts +4 -0
- package/dist/src/query/index.d.ts.map +1 -0
- package/dist/src/query/registerSeedQueryLocalSource.d.ts +25 -0
- package/dist/src/query/registerSeedQueryLocalSource.d.ts.map +1 -0
- package/dist/src/services/publish/publishMachine.d.ts +1 -1
- package/dist/src/services/publish/publishMachine.d.ts.map +1 -1
- package/dist/src/services/write/writeProcessMachine.d.ts +2 -6
- package/dist/src/services/write/writeProcessMachine.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/dist/{syncDbWithEas-DMOJHtkP.js → syncDbWithEas-ceVUuWSZ.js} +52 -54
- package/dist/syncDbWithEas-ceVUuWSZ.js.map +1 -0
- package/dist/{updateSeedRevokedAt-Ba0OhDQj.js → updateSeedRevokedAt-CtRjZiyh.js} +2 -2
- package/dist/{updateSeedRevokedAt-Ba0OhDQj.js.map → updateSeedRevokedAt-CtRjZiyh.js.map} +1 -1
- package/package.json +23 -6
- package/dist/ModelProperty-D-ysg8zA.js.map +0 -1
- package/dist/cjs/index-9Z2FOvLD.js.map +0 -1
- package/dist/cjs/index-vk2DeF2D.js.map +0 -1
- package/dist/cjs/ownership-DhWda0J9.js +0 -105
- package/dist/cjs/ownership-DhWda0J9.js.map +0 -1
- package/dist/cjs/syncDbWithEas-Dht3_7UD.js.map +0 -1
- package/dist/constants-B5S5JPDK.js.map +0 -1
- package/dist/eas-D9b7z2Wn.js.map +0 -1
- package/dist/getPublishPayload-CNYsn8-6.js.map +0 -1
- package/dist/index--F3Wolt5.js.map +0 -1
- package/dist/index-QMrBK-L3.js.map +0 -1
- package/dist/index-oi4roUVf.js +0 -22
- package/dist/index-oi4roUVf.js.map +0 -1
- package/dist/ownership-BF_ZUKIp.js +0 -105
- package/dist/ownership-BF_ZUKIp.js.map +0 -1
- package/dist/property-BdyDfcSc.js.map +0 -1
- package/dist/syncDbWithEas-DMOJHtkP.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { waitFor, fromCallback, fromPromise, setup, assign, stateIn, createActor, isMachineSnapshot } from 'xstate';
|
|
2
|
-
import {
|
|
2
|
+
import { a as BaseDb, m as models$1, p as properties, r as seeds, j as modelUids, v as versions, b as metadata$1, s as schemas, i as modelSchemas, B as BaseFileManager, c as appState, f as easSyncProcesses, t as BasePathResolver, h as htmlEmbeddedImageCoPublish, d as arweaveL1FinalizeJobs, q as publishProcesses } from './BasePathResolver-DWY_hb8w.js';
|
|
3
3
|
import { eq, and, isNotNull, not, or, max, count, getTableColumns, sql, isNull, desc, inArray, gt } from 'drizzle-orm';
|
|
4
|
-
import { n as normalizeDataType, t as toSnakeCase, o as MachineIds,
|
|
4
|
+
import { n as normalizeDataType, t as toSnakeCase, o as MachineIds, v as getStorageTransactionIdForSeedUid, w as convertTxIdToImage, M as ModelPropertyDataTypes, x as getDataTypeFromString, y as getMimeType, l as getCorrectId, z as ClientManagerEvents, C as ClientManagerState, d as TProperty } from './constants-B7aNfB_1.js';
|
|
5
5
|
import debug from 'debug';
|
|
6
6
|
import { customAlphabet } from 'nanoid';
|
|
7
7
|
import { alphanumeric } from 'nanoid-dictionary';
|
|
8
|
-
import { writeModelToDb, writePropertyToDb, addSchemaToDb, getAddressesForItemsFilter, getAllAddressesFromDb, escapeSqliteString, getPropertyIdForModelAndName, loadModelsFromDbForSchema,
|
|
8
|
+
import { writeModelToDb, writePropertyToDb, addSchemaToDb, getAddressesForItemsFilter, getAllAddressesFromDb, escapeSqliteString, getPropertyIdForModelAndName, loadModelsFromDbForSchema, getOwnedAddressesFromDb, getWatchedAddressesFromDb, renameModelInDb } from './db-Bad8QKfZ.js';
|
|
9
9
|
import pluralize from 'pluralize';
|
|
10
10
|
import { BaseQueryClient, BaseEasClient, GET_SCHEMAS, getSchemaUidForModelFromCache, setSchemaUidForModel, GET_PROPERTIES, pickLatestPropertyAttestationsByRefAndSchema, isValidEasAttestationUid, getEasSchemaUidForSchemaDefinition, GET_FILES_METADATA, GET_SCHEMA_BY_NAME } from '@seedprotocol/eas';
|
|
11
11
|
import { ZERO_BYTES32, INTERNAL_PROPERTY_NAMES, INTERNAL_DATA_TYPES, ImageSize, PROPERTY_NAMES_EXEMPT_FROM_ID_SUFFIX_STRIP, isInternalSchema, INTERNAL_SCHEMA_IDS, SEED_PROTOCOL_SCHEMA_NAME, CLIENT_NOT_INITIALIZED } from './constants-DMHTYMgJ.js';
|
|
@@ -14,6 +14,7 @@ import { startCase, throttle, upperFirst, camelCase, orderBy } from 'lodash-es';
|
|
|
14
14
|
import { toSnakeCase as toSnakeCase$1 } from 'drizzle-orm/casing';
|
|
15
15
|
import { ensureReadGatewaySelected, BaseArweaveClient, getResolvedSeedGatewayEndpoints, getReadGatewayHostsForConfig, getDefaultArweaveReadGatewayHostsOrdered, getArweaveReadGatewayHostsForPrimary, seedGatewayConfigFromSeedConfig, resolveSeedGatewayEndpoints, setResolvedSeedGatewayEndpoints, DEFAULT_ARWEAVE_HOST } from '@seedprotocol/arweave';
|
|
16
16
|
import * as sha3 from 'js-sha3';
|
|
17
|
+
import { clearLocalQuerySource, registerLocalQuerySource, getSeed } from '@seedprotocol/query';
|
|
17
18
|
import { Type } from '@sinclair/typebox';
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -282,7 +283,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
282
283
|
return;
|
|
283
284
|
}
|
|
284
285
|
try {
|
|
285
|
-
const mod = await import('./ModelProperty-
|
|
286
|
+
const mod = await import('./ModelProperty-DGJf78CS.js');
|
|
286
287
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
287
288
|
if (!ModelProperty) {
|
|
288
289
|
logger$s('createPropertyInstances: ModelProperty not available from dynamic import');
|
|
@@ -466,7 +467,7 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
466
467
|
// Step 2: Fallback to Schema context (only if database doesn't have the model)
|
|
467
468
|
// This handles the case where model exists in schema file but not yet in database
|
|
468
469
|
try {
|
|
469
|
-
const _mod_0 = await import('./Schema-
|
|
470
|
+
const _mod_0 = await import('./Schema-Drmce3q-.js');
|
|
470
471
|
const _ns_0 = _mod_0.b;
|
|
471
472
|
const schemaMod = _ns_0;
|
|
472
473
|
const { Schema } = schemaMod;
|
|
@@ -616,11 +617,11 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
616
617
|
}
|
|
617
618
|
// Also check database for models (in case they're persisted but not in Schema context)
|
|
618
619
|
if (db) {
|
|
619
|
-
const _mod_1 = await import('./BasePathResolver-
|
|
620
|
+
const _mod_1 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
620
621
|
const _ns_1 = _mod_1.x;
|
|
621
622
|
const modelSchemaSchemaMod = _ns_1;
|
|
622
623
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
623
|
-
const _mod_2 = await import('./BasePathResolver-
|
|
624
|
+
const _mod_2 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
624
625
|
const _ns_2 = _mod_2.S;
|
|
625
626
|
const schemaSchemaMod = _ns_2;
|
|
626
627
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
@@ -716,7 +717,7 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
716
717
|
}
|
|
717
718
|
// Mark schema as draft when a new model is created so saveNewVersion() can persist it
|
|
718
719
|
try {
|
|
719
|
-
const _mod_3 = await import('./Schema-
|
|
720
|
+
const _mod_3 = await import('./Schema-Drmce3q-.js');
|
|
720
721
|
const _ns_3 = _mod_3.b;
|
|
721
722
|
const schemaMod = _ns_3;
|
|
722
723
|
const { Schema } = schemaMod;
|
|
@@ -762,10 +763,10 @@ const validateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
762
763
|
const _validateModel = async () => {
|
|
763
764
|
try {
|
|
764
765
|
// Use dynamic imports to break circular dependencies
|
|
765
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
766
|
+
const validationServiceMod = await import('./SchemaValidationService-a_sfnpDV.js');
|
|
766
767
|
const { SchemaValidationService } = validationServiceMod;
|
|
767
768
|
const validationService = new SchemaValidationService();
|
|
768
|
-
const _mod_4 = await import('./Schema-
|
|
769
|
+
const _mod_4 = await import('./Schema-Drmce3q-.js');
|
|
769
770
|
const _ns_4 = _mod_4.b;
|
|
770
771
|
const schemaMod = _ns_4;
|
|
771
772
|
const { Schema } = schemaMod;
|
|
@@ -877,7 +878,7 @@ const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
|
877
878
|
return;
|
|
878
879
|
}
|
|
879
880
|
logger$q(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
|
|
880
|
-
const mod = await import('./ModelProperty-
|
|
881
|
+
const mod = await import('./ModelProperty-DGJf78CS.js');
|
|
881
882
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
882
883
|
if (!ModelProperty) {
|
|
883
884
|
logger$q('ModelProperty not available from dynamic import');
|
|
@@ -980,7 +981,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
980
981
|
const structureMsg = `[validateEntity] Validating model structure`;
|
|
981
982
|
logger$p(structureMsg);
|
|
982
983
|
// Use existing Model validation
|
|
983
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
984
|
+
const validationServiceMod = await import('./SchemaValidationService-a_sfnpDV.js');
|
|
984
985
|
const { SchemaValidationService } = validationServiceMod;
|
|
985
986
|
const validationService = new SchemaValidationService();
|
|
986
987
|
// Validate model structure
|
|
@@ -998,7 +999,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
998
999
|
if (entityInput.entityData.schemaName) {
|
|
999
1000
|
try {
|
|
1000
1001
|
logger$p(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
|
|
1001
|
-
const _mod_5 = await import('./Schema-
|
|
1002
|
+
const _mod_5 = await import('./Schema-Drmce3q-.js');
|
|
1002
1003
|
const _ns_5 = _mod_5.b;
|
|
1003
1004
|
const schemaMod = _ns_5;
|
|
1004
1005
|
const { Schema } = schemaMod;
|
|
@@ -1036,7 +1037,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
1036
1037
|
}
|
|
1037
1038
|
else if (entityInput.entityType === 'modelProperty') {
|
|
1038
1039
|
// Use existing ModelProperty validation
|
|
1039
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
1040
|
+
const validationServiceMod = await import('./SchemaValidationService-a_sfnpDV.js');
|
|
1040
1041
|
const { SchemaValidationService } = validationServiceMod;
|
|
1041
1042
|
const validationService = new SchemaValidationService();
|
|
1042
1043
|
// Validate property structure
|
|
@@ -1051,7 +1052,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
1051
1052
|
// If schema name and model name provided, validate against schema
|
|
1052
1053
|
if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
|
|
1053
1054
|
try {
|
|
1054
|
-
const _mod_6 = await import('./Schema-
|
|
1055
|
+
const _mod_6 = await import('./Schema-Drmce3q-.js');
|
|
1055
1056
|
const _ns_6 = _mod_6.b;
|
|
1056
1057
|
const schemaMod = _ns_6;
|
|
1057
1058
|
const { Schema } = schemaMod;
|
|
@@ -1082,7 +1083,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
1082
1083
|
}
|
|
1083
1084
|
else if (entityInput.entityType === 'schema') {
|
|
1084
1085
|
// Schema validation - use existing validation
|
|
1085
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
1086
|
+
const validationServiceMod = await import('./SchemaValidationService-a_sfnpDV.js');
|
|
1086
1087
|
const { SchemaValidationService } = validationServiceMod;
|
|
1087
1088
|
const validationService = new SchemaValidationService();
|
|
1088
1089
|
const schemaResult = validationService.validateSchema(entityInput.entityData);
|
|
@@ -1155,7 +1156,7 @@ const writeToDatabase = fromCallback(({ sendBack, input }) => {
|
|
|
1155
1156
|
// initial write completes is not overwritten by the stale requestWrite payload.
|
|
1156
1157
|
let dataToWrite = input.entityData;
|
|
1157
1158
|
try {
|
|
1158
|
-
const mod = await import('./ModelProperty-
|
|
1159
|
+
const mod = await import('./ModelProperty-DGJf78CS.js');
|
|
1159
1160
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1160
1161
|
if (ModelProperty && typeof ModelProperty.getById === 'function') {
|
|
1161
1162
|
const instance = ModelProperty.getById(input.entityId);
|
|
@@ -1535,7 +1536,7 @@ const modelMachine = setup({
|
|
|
1535
1536
|
// Create ModelProperty instances for any new property IDs
|
|
1536
1537
|
if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
|
|
1537
1538
|
// Import and create instances asynchronously (fire-and-forget)
|
|
1538
|
-
import('./ModelProperty-
|
|
1539
|
+
import('./ModelProperty-DGJf78CS.js').then(({ ModelProperty }) => {
|
|
1539
1540
|
const createPromises = newPropertyIds.map(async (propertyFileId) => {
|
|
1540
1541
|
try {
|
|
1541
1542
|
const property = await ModelProperty.createById(propertyFileId);
|
|
@@ -2433,7 +2434,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
2433
2434
|
const schemaNameToTry = model$1?.schemaName;
|
|
2434
2435
|
if (schemaNameToTry) {
|
|
2435
2436
|
try {
|
|
2436
|
-
const _mod_7 = await import('./Schema-
|
|
2437
|
+
const _mod_7 = await import('./Schema-Drmce3q-.js');
|
|
2437
2438
|
const _ns_7 = _mod_7.b;
|
|
2438
2439
|
const { Schema } = _ns_7;
|
|
2439
2440
|
const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
|
|
@@ -2467,7 +2468,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
2467
2468
|
if (Object.keys(propertySchemas).length === 0) {
|
|
2468
2469
|
try {
|
|
2469
2470
|
const { listCompleteSchemaFiles } = await Promise.resolve().then(function () { return schema; });
|
|
2470
|
-
const _mod_8 = await import('./BasePathResolver-
|
|
2471
|
+
const _mod_8 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
2471
2472
|
const _ns_8 = _mod_8.w;
|
|
2472
2473
|
const { BaseFileManager } = _ns_8;
|
|
2473
2474
|
const schemaFiles = await listCompleteSchemaFiles();
|
|
@@ -2486,7 +2487,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
2486
2487
|
}
|
|
2487
2488
|
}
|
|
2488
2489
|
if (Object.keys(propertySchemas).length === 0) {
|
|
2489
|
-
const schemaMod = await import('./index-
|
|
2490
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
2490
2491
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
2491
2492
|
const KNOWN_MODEL_FALLBACKS = {
|
|
2492
2493
|
Post: {
|
|
@@ -2533,7 +2534,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
2533
2534
|
// Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
|
|
2534
2535
|
let propSchema = propertySchemas[propertyName];
|
|
2535
2536
|
if (!propSchema && isRefTypeFromMeta) {
|
|
2536
|
-
const schemaMod = await import('./index-
|
|
2537
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
2537
2538
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
2538
2539
|
propSchema = {
|
|
2539
2540
|
dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
|
|
@@ -2790,9 +2791,9 @@ const runPublish = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2790
2791
|
sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
|
|
2791
2792
|
return;
|
|
2792
2793
|
}
|
|
2793
|
-
const getPublishUploadsMod = await import('./getPublishUploads-
|
|
2794
|
+
const getPublishUploadsMod = await import('./getPublishUploads-CJjfqJi9.js');
|
|
2794
2795
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
2795
|
-
const getPublishPayloadMod = await import('./getPublishPayload-
|
|
2796
|
+
const getPublishPayloadMod = await import('./getPublishPayload-BEO52UOv.js');
|
|
2796
2797
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
2797
2798
|
const uploads = await getPublishUploads(item);
|
|
2798
2799
|
let uploadedTransactions = [];
|
|
@@ -3173,6 +3174,14 @@ async function getLatestPublishedVersionRow(seedLocalId) {
|
|
|
3173
3174
|
}
|
|
3174
3175
|
|
|
3175
3176
|
const logger$j = debug('seedSdk:db:read:getItemData');
|
|
3177
|
+
/**
|
|
3178
|
+
* Assemble flat ItemData for Item / liveQuery / draft-head authoring.
|
|
3179
|
+
*
|
|
3180
|
+
* For **published chain JSON** (Seed → latest attested Version → properties),
|
|
3181
|
+
* prefer `getPublishedSeedRecord` from `@seedprotocol/sdk` or
|
|
3182
|
+
* `getSeed` / `queryBySchema` from `@seedprotocol/query`. This function remains
|
|
3183
|
+
* the correct path for local-head / draft-wins property selection used by Item.
|
|
3184
|
+
*/
|
|
3176
3185
|
const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
3177
3186
|
if (!seedLocalId && !seedUid) {
|
|
3178
3187
|
throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
|
|
@@ -3632,7 +3641,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
3632
3641
|
const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
|
|
3633
3642
|
const _resolveRelatedValue = async () => {
|
|
3634
3643
|
// Use dynamic import to break circular dependency
|
|
3635
|
-
const schemaMod = await import('./index-
|
|
3644
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
3636
3645
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
3637
3646
|
if (!propertyValue || !isRelation || populatedFromDb) {
|
|
3638
3647
|
return;
|
|
@@ -4494,7 +4503,7 @@ async function fetchHtmlViaRawAcrossGateways(txId) {
|
|
|
4494
4503
|
return undefined;
|
|
4495
4504
|
try {
|
|
4496
4505
|
const resolved = getResolvedSeedGatewayEndpoints();
|
|
4497
|
-
if (!resolved || resolved.activePath !== 'hyper-sidecar') {
|
|
4506
|
+
if (!resolved || (resolved.activePath !== 'hyper-sidecar' && resolved.activePath !== 'http-proxy')) {
|
|
4498
4507
|
const { ensureReadGatewaySelected } = await import('@seedprotocol/arweave');
|
|
4499
4508
|
await ensureReadGatewaySelected().catch(() => { });
|
|
4500
4509
|
}
|
|
@@ -4635,7 +4644,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
4635
4644
|
// to use dynamically imported ModelPropertyDataTypes
|
|
4636
4645
|
const _hydrateFromDb = async () => {
|
|
4637
4646
|
// Use dynamic import to break circular dependency
|
|
4638
|
-
const schemaMod = await import('./index-
|
|
4647
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
4639
4648
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
4640
4649
|
const appDb = BaseDb.getAppDb();
|
|
4641
4650
|
const whereClauses = [];
|
|
@@ -4998,14 +5007,14 @@ const loadOrCreateProperty = fromCallback(({ sendBack, input: { context } }) =>
|
|
|
4998
5007
|
};
|
|
4999
5008
|
// Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
|
|
5000
5009
|
try {
|
|
5001
|
-
const { getPropertySchema } = await import('./property-
|
|
5010
|
+
const { getPropertySchema } = await import('./property-DIN1zQ_c.js');
|
|
5002
5011
|
let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName);
|
|
5003
5012
|
if (!schemaFromFile?.validation) {
|
|
5004
5013
|
// Fallback: get validation from schemaData in database (Schema context may not be loaded yet)
|
|
5005
|
-
const _mod_9 = await import('./BasePathResolver-
|
|
5014
|
+
const _mod_9 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
5006
5015
|
const _ns_9 = _mod_9.S;
|
|
5007
5016
|
const { schemas: schemasTable } = _ns_9;
|
|
5008
|
-
const _mod_10 = await import('./BasePathResolver-
|
|
5017
|
+
const _mod_10 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
5009
5018
|
const _ns_10 = _mod_10.x;
|
|
5010
5019
|
const { modelSchemas } = _ns_10;
|
|
5011
5020
|
const modelSchemaRows = await db
|
|
@@ -5467,9 +5476,9 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
5467
5476
|
}
|
|
5468
5477
|
const _analyzeInput = async () => {
|
|
5469
5478
|
// Use dynamic import to break circular dependency
|
|
5470
|
-
const schemaMod = await import('./index-
|
|
5479
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
5471
5480
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
5472
|
-
const { SchemaValidationService } = await import('./SchemaValidationService-
|
|
5481
|
+
const { SchemaValidationService } = await import('./SchemaValidationService-a_sfnpDV.js');
|
|
5473
5482
|
let propertyName = propertyNameRaw;
|
|
5474
5483
|
if (!propertyName) {
|
|
5475
5484
|
throw new Error('propertyName is required');
|
|
@@ -5667,7 +5676,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
|
|
|
5667
5676
|
propertyRecordSchema?.validation &&
|
|
5668
5677
|
metadataValues.propertyValue != null &&
|
|
5669
5678
|
metadataValues.propertyValue !== '') {
|
|
5670
|
-
const { SchemaValidationService } = await import('./SchemaValidationService-
|
|
5679
|
+
const { SchemaValidationService } = await import('./SchemaValidationService-a_sfnpDV.js');
|
|
5671
5680
|
const validationService = new SchemaValidationService();
|
|
5672
5681
|
const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, normalizeDataType(propertyRecordSchema.dataType), propertyRecordSchema.validation, propertyRecordSchema.refValueType
|
|
5673
5682
|
? normalizeDataType(String(propertyRecordSchema.refValueType))
|
|
@@ -6260,7 +6269,7 @@ const saveRelation = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
6260
6269
|
}
|
|
6261
6270
|
const _saveRelation = async () => {
|
|
6262
6271
|
// Use dynamic import to break circular dependency
|
|
6263
|
-
const schemaMod = await import('./index-
|
|
6272
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
6264
6273
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
6265
6274
|
if (!propertyNameRaw) {
|
|
6266
6275
|
throw new Error('propertyName is required');
|
|
@@ -7304,7 +7313,7 @@ class ItemProperty {
|
|
|
7304
7313
|
return;
|
|
7305
7314
|
}
|
|
7306
7315
|
// Use dynamic import to break circular dependency
|
|
7307
|
-
const schemaMod = await import('./index-
|
|
7316
|
+
const schemaMod = await import('./index-DNOCl06b.js');
|
|
7308
7317
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
7309
7318
|
const { context } = snapshot;
|
|
7310
7319
|
const { propertyRecordSchema } = context;
|
|
@@ -7475,7 +7484,7 @@ class ItemProperty {
|
|
|
7475
7484
|
const normalizedRefValueType = normalizeDataType(propertyRecordSchema?.refValueType);
|
|
7476
7485
|
const propertyNames = getMetadataPropertyNamesForQuery(propertyName, normalizedDataType, normalizedRefValueType);
|
|
7477
7486
|
const propertyNameVariant = propertyNames.length > 1 ? propertyNames[1] : undefined;
|
|
7478
|
-
const _mod_11 = await import('./index-
|
|
7487
|
+
const _mod_11 = await import('./index-DrEkRiuK.js');
|
|
7479
7488
|
const _ns_11 = _mod_11.s;
|
|
7480
7489
|
const seedSchemaMod = _ns_11;
|
|
7481
7490
|
const { metadata } = seedSchemaMod;
|
|
@@ -8215,7 +8224,7 @@ class ItemProperty {
|
|
|
8215
8224
|
}
|
|
8216
8225
|
async save() {
|
|
8217
8226
|
const ctx = this._getSnapshotContext();
|
|
8218
|
-
const { assertItemOwned } = await
|
|
8227
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
8219
8228
|
await assertItemOwned({
|
|
8220
8229
|
seedLocalId: ctx?.seedLocalId ?? undefined,
|
|
8221
8230
|
seedUid: ctx?.seedUid ?? undefined,
|
|
@@ -8308,7 +8317,7 @@ class ItemProperty {
|
|
|
8308
8317
|
if (!propertyName || (!seedLocalId && !seedUid))
|
|
8309
8318
|
return;
|
|
8310
8319
|
if (db) {
|
|
8311
|
-
const _mod_12 = await import('./index-
|
|
8320
|
+
const _mod_12 = await import('./index-DrEkRiuK.js');
|
|
8312
8321
|
const _ns_12 = _mod_12.s;
|
|
8313
8322
|
const seedSchemaMod = _ns_12;
|
|
8314
8323
|
const { metadata } = seedSchemaMod;
|
|
@@ -8556,7 +8565,7 @@ class Item {
|
|
|
8556
8565
|
});
|
|
8557
8566
|
};
|
|
8558
8567
|
this.unpublish = async () => {
|
|
8559
|
-
const { assertItemOwned } = await
|
|
8568
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
8560
8569
|
const { getRevokeExecutor } = await Promise.resolve().then(function () { return publishConfig; });
|
|
8561
8570
|
await assertItemOwned(this);
|
|
8562
8571
|
const seedUid = this.seedUid;
|
|
@@ -8580,7 +8589,7 @@ class Item {
|
|
|
8580
8589
|
this._service.send({ type: 'updateContext', revokedAt });
|
|
8581
8590
|
};
|
|
8582
8591
|
this.publish = async () => {
|
|
8583
|
-
const { assertItemOwned } = await
|
|
8592
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
8584
8593
|
await assertItemOwned(this);
|
|
8585
8594
|
this._service.send({ type: 'startPublish' });
|
|
8586
8595
|
return new Promise((resolve, reject) => {
|
|
@@ -8616,12 +8625,12 @@ class Item {
|
|
|
8616
8625
|
};
|
|
8617
8626
|
this.getPublishUploads = async (options) => {
|
|
8618
8627
|
// Use dynamic import to break circular dependency
|
|
8619
|
-
const getPublishUploadsMod = await import('./getPublishUploads-
|
|
8628
|
+
const getPublishUploadsMod = await import('./getPublishUploads-CJjfqJi9.js');
|
|
8620
8629
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
8621
8630
|
return await getPublishUploads(this, [], undefined, options);
|
|
8622
8631
|
};
|
|
8623
8632
|
this.getPublishPayload = async (uploadedTransactions, options) => {
|
|
8624
|
-
const getPublishPayloadMod = await import('./getPublishPayload-
|
|
8633
|
+
const getPublishPayloadMod = await import('./getPublishPayload-BEO52UOv.js');
|
|
8625
8634
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
8626
8635
|
return await getPublishPayload(this, uploadedTransactions, options);
|
|
8627
8636
|
};
|
|
@@ -9093,11 +9102,11 @@ class Item {
|
|
|
9093
9102
|
let modelRecords;
|
|
9094
9103
|
// If we have a schema name, join with modelSchemas to filter by schema
|
|
9095
9104
|
if (schemaName) {
|
|
9096
|
-
const _mod_13 = await import('./BasePathResolver-
|
|
9105
|
+
const _mod_13 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
9097
9106
|
const _ns_13 = _mod_13.x;
|
|
9098
9107
|
const modelSchemaSchemaMod = _ns_13;
|
|
9099
9108
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
9100
|
-
const _mod_14 = await import('./BasePathResolver-
|
|
9109
|
+
const _mod_14 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
9101
9110
|
const _ns_14 = _mod_14.S;
|
|
9102
9111
|
const schemaSchemaMod = _ns_14;
|
|
9103
9112
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
@@ -9278,6 +9287,39 @@ class Item {
|
|
|
9278
9287
|
}
|
|
9279
9288
|
return null;
|
|
9280
9289
|
}
|
|
9290
|
+
/**
|
|
9291
|
+
* Drop cached Item instances for the given seed local ids / uids without soft-deleting DB rows.
|
|
9292
|
+
* Used by local purge (`removeLocalCopiesForAddresses`) before hard-deleting rows.
|
|
9293
|
+
*/
|
|
9294
|
+
static dropCachedInstancesForSeedIds(ids) {
|
|
9295
|
+
const uniqueIds = [
|
|
9296
|
+
...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0)),
|
|
9297
|
+
];
|
|
9298
|
+
const seenInstances = new Set();
|
|
9299
|
+
for (const id of uniqueIds) {
|
|
9300
|
+
const entry = this.findItemInstanceCacheEntryById(id);
|
|
9301
|
+
if (entry && !seenInstances.has(entry.instance)) {
|
|
9302
|
+
seenInstances.add(entry.instance);
|
|
9303
|
+
const instance = entry.instance;
|
|
9304
|
+
const cacheKeys = this.collectInstanceCacheKeysForInstance(instance);
|
|
9305
|
+
clearDestroySubscriptions(instance, {
|
|
9306
|
+
instanceState: itemInstanceState,
|
|
9307
|
+
onUnload: (inst) => inst._subscription?.unsubscribe(),
|
|
9308
|
+
});
|
|
9309
|
+
forceRemoveFromCaches(instance, {
|
|
9310
|
+
getCacheKeys: () => cacheKeys,
|
|
9311
|
+
caches: [Item.instanceCache],
|
|
9312
|
+
});
|
|
9313
|
+
try {
|
|
9314
|
+
instance._service.stop();
|
|
9315
|
+
}
|
|
9316
|
+
catch {
|
|
9317
|
+
// Service may already be stopped
|
|
9318
|
+
}
|
|
9319
|
+
}
|
|
9320
|
+
ItemProperty.clearInstanceCacheForItem(id);
|
|
9321
|
+
}
|
|
9322
|
+
}
|
|
9281
9323
|
/**
|
|
9282
9324
|
* Create Item instance by ID (queries database if not in cache)
|
|
9283
9325
|
* The ID can be either seedUid or seedLocalId
|
|
@@ -9366,7 +9408,7 @@ class Item {
|
|
|
9366
9408
|
if (!appDb || Item.instanceCache.size === 0) {
|
|
9367
9409
|
return;
|
|
9368
9410
|
}
|
|
9369
|
-
const _mod_15 = await import('./index-
|
|
9411
|
+
const _mod_15 = await import('./index-DrEkRiuK.js');
|
|
9370
9412
|
const _ns_15 = _mod_15.s;
|
|
9371
9413
|
const { metadata } = _ns_15;
|
|
9372
9414
|
const { eq, and } = await import('drizzle-orm');
|
|
@@ -9817,7 +9859,7 @@ class Item {
|
|
|
9817
9859
|
itemActor.send(event);
|
|
9818
9860
|
};
|
|
9819
9861
|
try {
|
|
9820
|
-
const _mod_16 = await import('./index-
|
|
9862
|
+
const _mod_16 = await import('./index-DrEkRiuK.js');
|
|
9821
9863
|
const _ns_16 = _mod_16.s;
|
|
9822
9864
|
const seedSchemaMod = _ns_16;
|
|
9823
9865
|
const { seeds, versions, metadata } = seedSchemaMod;
|
|
@@ -10123,7 +10165,7 @@ class Item {
|
|
|
10123
10165
|
* Destroy the item: soft delete in DB, remove from caches, clean up subscriptions, stop service.
|
|
10124
10166
|
*/
|
|
10125
10167
|
async destroy() {
|
|
10126
|
-
const { assertItemOwned } = await
|
|
10168
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
10127
10169
|
await assertItemOwned(this);
|
|
10128
10170
|
const context = this._getSnapshotContext();
|
|
10129
10171
|
const cacheKeys = Item.collectInstanceCacheKeysForInstance(this);
|
|
@@ -10279,7 +10321,7 @@ const runEasSync = fromPromise(async ({ input, }) => {
|
|
|
10279
10321
|
requestPayload: input.requestPayload,
|
|
10280
10322
|
persistedSnapshot: input.runningSnapshot,
|
|
10281
10323
|
});
|
|
10282
|
-
const { runSyncFromEas } = await import('./syncDbWithEas-
|
|
10324
|
+
const { runSyncFromEas } = await import('./syncDbWithEas-ceVUuWSZ.js');
|
|
10283
10325
|
try {
|
|
10284
10326
|
await runSyncFromEas(toRunSyncArg(input.options));
|
|
10285
10327
|
await finalizeEasSyncProcessRow(rowId, {
|
|
@@ -10558,7 +10600,7 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
|
|
|
10558
10600
|
}
|
|
10559
10601
|
// Prefer the condition-resolved factory when available; fall back to explicit
|
|
10560
10602
|
// platform imports so source/vitest resolution stays reliable.
|
|
10561
|
-
const { configurePlatform } = await import('./configurePlatform-
|
|
10603
|
+
const { configurePlatform } = await import('./configurePlatform-CXQCT7N8.js');
|
|
10562
10604
|
if (isBrowser()) {
|
|
10563
10605
|
const { createPlatformServices } = await import('./platform.browser.js');
|
|
10564
10606
|
configurePlatform(createPlatformServices());
|
|
@@ -10636,6 +10678,7 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
|
|
|
10636
10678
|
gatewayHyperKey: resolvedGateway.gatewayHyperKey,
|
|
10637
10679
|
gatewaySidecarHost: gatewayConfig.hyper?.localSidecarHost,
|
|
10638
10680
|
gatewaySidecarPort: gatewayConfig.hyper?.localSidecarPort,
|
|
10681
|
+
gatewayProxyBaseUrl: resolvedGateway.proxyBaseUrl ?? gatewayConfig.proxyBaseUrl,
|
|
10639
10682
|
addresses: normalizedAddresses.owned,
|
|
10640
10683
|
ownedAddresses: normalizedAddresses.owned,
|
|
10641
10684
|
watchedAddresses: normalizedAddresses.watched,
|
|
@@ -10645,7 +10688,7 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
|
|
|
10645
10688
|
schema,
|
|
10646
10689
|
syncFromEasOnAddressChange: options.syncFromEasOnAddressChange ?? true,
|
|
10647
10690
|
} });
|
|
10648
|
-
if (resolvedGateway.activePath !== 'hyper-sidecar') {
|
|
10691
|
+
if (resolvedGateway.activePath !== 'hyper-sidecar' && resolvedGateway.activePath !== 'http-proxy') {
|
|
10649
10692
|
void ensureReadGatewaySelected().catch(() => {
|
|
10650
10693
|
/* non-blocking warm-up for read gateway probe */
|
|
10651
10694
|
});
|
|
@@ -10984,7 +11027,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
10984
11027
|
const logger$5 = debug('seedSdk:client:actors:saveConfig');
|
|
10985
11028
|
const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
10986
11029
|
logger$5('saveConfig starting');
|
|
10987
|
-
const { endpoints, addresses, ownedAddresses, watchedAddresses, arweaveDomain, uploadApiBaseUrl, gatewayTransport, gatewayHyperKey, gatewaySidecarHost, gatewaySidecarPort, } = context;
|
|
11030
|
+
const { endpoints, addresses, ownedAddresses, watchedAddresses, arweaveDomain, uploadApiBaseUrl, gatewayTransport, gatewayHyperKey, gatewaySidecarHost, gatewaySidecarPort, gatewayProxyBaseUrl, } = context;
|
|
10988
11031
|
// Validate endpoints - required for proper initialization
|
|
10989
11032
|
// If endpoints are missing or invalid, initialization should fail
|
|
10990
11033
|
if (!endpoints || !endpoints.filePaths || !endpoints.files) {
|
|
@@ -11064,6 +11107,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
11064
11107
|
if (gatewaySidecarPort != null) {
|
|
11065
11108
|
await persistKey('gatewaySidecarPort', String(gatewaySidecarPort));
|
|
11066
11109
|
}
|
|
11110
|
+
await persistKey('gatewayProxyBaseUrl', gatewayProxyBaseUrl);
|
|
11067
11111
|
}
|
|
11068
11112
|
catch (error) {
|
|
11069
11113
|
logger$5('[internal/actors] [saveConfig] Error saving config:', error);
|
|
@@ -11185,6 +11229,50 @@ const readSchema = async (name, version, schemaFileId) => {
|
|
|
11185
11229
|
throw new Error(`Failed to read schema ${name} v${version}: ${error instanceof Error ? error.message : String(error)}`);
|
|
11186
11230
|
}
|
|
11187
11231
|
};
|
|
11232
|
+
/**
|
|
11233
|
+
* Update an existing schema file
|
|
11234
|
+
* @param schema - The updated schema object (must have same name and version as existing)
|
|
11235
|
+
* @param schemaFileId - Schema file ID (required)
|
|
11236
|
+
* @throws Error if schema doesn't exist
|
|
11237
|
+
*/
|
|
11238
|
+
async function updateSchema(schema, schemaFileId) {
|
|
11239
|
+
if (!schema.name || !schema.version) {
|
|
11240
|
+
throw new Error('Schema must have a name and version');
|
|
11241
|
+
}
|
|
11242
|
+
const filePath = getSchemaFilePath$1(schema.name, schema.version, schemaFileId);
|
|
11243
|
+
// Check if schema exists
|
|
11244
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
11245
|
+
if (!exists) {
|
|
11246
|
+
throw new Error(`Schema ${schema.name} v${schema.version} does not exist`);
|
|
11247
|
+
}
|
|
11248
|
+
// Write updated schema to file
|
|
11249
|
+
const content = JSON.stringify(schema, null, 2);
|
|
11250
|
+
await BaseFileManager.saveFile(filePath, content);
|
|
11251
|
+
}
|
|
11252
|
+
/**
|
|
11253
|
+
* Delete a schema file
|
|
11254
|
+
* @param name - The name of the schema
|
|
11255
|
+
* @param version - The version of the schema
|
|
11256
|
+
* @param schemaFileId - Schema file ID (required)
|
|
11257
|
+
* @throws Error if schema doesn't exist
|
|
11258
|
+
*/
|
|
11259
|
+
async function deleteSchema(name, version, schemaFileId) {
|
|
11260
|
+
const filePath = getSchemaFilePath$1(name, version, schemaFileId);
|
|
11261
|
+
// Check if schema exists
|
|
11262
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
11263
|
+
if (!exists) {
|
|
11264
|
+
throw new Error(`Schema ${name} v${version} does not exist`);
|
|
11265
|
+
}
|
|
11266
|
+
// Delete the file
|
|
11267
|
+
const fs = await BaseFileManager.getFs();
|
|
11268
|
+
BaseFileManager.getPathModule();
|
|
11269
|
+
try {
|
|
11270
|
+
await fs.promises.unlink(filePath);
|
|
11271
|
+
}
|
|
11272
|
+
catch (error) {
|
|
11273
|
+
throw new Error(`Failed to delete schema ${name} v${version}: ${error instanceof Error ? error.message : String(error)}`);
|
|
11274
|
+
}
|
|
11275
|
+
}
|
|
11188
11276
|
/**
|
|
11189
11277
|
* List all schema files in the working directory
|
|
11190
11278
|
* Only returns files that are NOT already complete schema files (i.e., files without $schema field)
|
|
@@ -11295,6 +11383,24 @@ async function listCompleteSchemaFiles() {
|
|
|
11295
11383
|
throw new Error(`Failed to list complete schemas: ${error instanceof Error ? error.message : String(error)}`);
|
|
11296
11384
|
}
|
|
11297
11385
|
}
|
|
11386
|
+
/**
|
|
11387
|
+
* Find a schema by name (returns the latest version if multiple versions exist)
|
|
11388
|
+
* @param name - The name of the schema
|
|
11389
|
+
* @returns The schema with the highest version, or null if not found
|
|
11390
|
+
*/
|
|
11391
|
+
async function findSchemaByName(name) {
|
|
11392
|
+
const schemas = await listCompleteSchemaFiles();
|
|
11393
|
+
const matchingSchemas = schemas.filter((s) => s.name === name);
|
|
11394
|
+
if (matchingSchemas.length === 0) {
|
|
11395
|
+
return null;
|
|
11396
|
+
}
|
|
11397
|
+
// Find the schema with the highest version
|
|
11398
|
+
const latest = matchingSchemas.reduce((prev, current) => current.version > prev.version ? current : prev);
|
|
11399
|
+
if (!latest.schemaFileId) {
|
|
11400
|
+
throw new Error(`Schema ${latest.name} v${latest.version} is missing schemaFileId`);
|
|
11401
|
+
}
|
|
11402
|
+
return readSchema(latest.name, latest.version, latest.schemaFileId);
|
|
11403
|
+
}
|
|
11298
11404
|
/**
|
|
11299
11405
|
* Get the latest version number for a schema by name
|
|
11300
11406
|
* Only considers complete schema files (with $schema field)
|
|
@@ -11327,6 +11433,27 @@ async function listLatestSchemaFiles() {
|
|
|
11327
11433
|
}
|
|
11328
11434
|
return Array.from(schemaMap.values());
|
|
11329
11435
|
}
|
|
11436
|
+
/**
|
|
11437
|
+
* Filter an array of schemas to only include the latest version for each schema name
|
|
11438
|
+
* Works with any object that has a name (via metadata.name or name property) and a version property
|
|
11439
|
+
* @param schemas - Array of schema objects
|
|
11440
|
+
* @returns Array containing only the latest version of each schema
|
|
11441
|
+
*/
|
|
11442
|
+
function filterLatestSchemas(schemas) {
|
|
11443
|
+
// Group by schema name and keep only the latest version of each
|
|
11444
|
+
const schemaMap = new Map();
|
|
11445
|
+
for (const schema of schemas) {
|
|
11446
|
+
const schemaName = schema.metadata?.name || schema.name;
|
|
11447
|
+
if (!schemaName) {
|
|
11448
|
+
continue; // Skip schemas without a name
|
|
11449
|
+
}
|
|
11450
|
+
const existing = schemaMap.get(schemaName);
|
|
11451
|
+
if (!existing || schema.version > existing.version) {
|
|
11452
|
+
schemaMap.set(schemaName, schema);
|
|
11453
|
+
}
|
|
11454
|
+
}
|
|
11455
|
+
return Array.from(schemaMap.values());
|
|
11456
|
+
}
|
|
11330
11457
|
/**
|
|
11331
11458
|
* Unified schema loading function that queries database first, then merges with files
|
|
11332
11459
|
* Returns all schemas with their draft status and source information
|
|
@@ -11520,6 +11647,62 @@ async function loadAllSchemasFromDb() {
|
|
|
11520
11647
|
}
|
|
11521
11648
|
return result;
|
|
11522
11649
|
}
|
|
11650
|
+
/**
|
|
11651
|
+
* Migration helper: Migrate existing file-based schemas to the database
|
|
11652
|
+
* This function should be called once to migrate existing schema files to the new database-first approach
|
|
11653
|
+
* All existing schemas will be marked as published (isDraft = false) since they already exist in files
|
|
11654
|
+
* @returns Number of schemas migrated
|
|
11655
|
+
*/
|
|
11656
|
+
async function migrateFileSchemasToDb() {
|
|
11657
|
+
const db = BaseDb.getAppDb();
|
|
11658
|
+
if (!db) {
|
|
11659
|
+
throw new Error('Database not found');
|
|
11660
|
+
}
|
|
11661
|
+
logger$4('Starting migration of file-based schemas to database');
|
|
11662
|
+
// Get all complete schema files
|
|
11663
|
+
const completeSchemas = await listCompleteSchemaFiles();
|
|
11664
|
+
let migratedCount = 0;
|
|
11665
|
+
for (const schemaFileInfo of completeSchemas) {
|
|
11666
|
+
try {
|
|
11667
|
+
// Read the schema file
|
|
11668
|
+
const content = await BaseFileManager.readFileAsString(schemaFileInfo.filePath);
|
|
11669
|
+
const schemaFile = JSON.parse(content);
|
|
11670
|
+
if (!schemaFile.$schema || !schemaFile.metadata?.name) {
|
|
11671
|
+
logger$4(`Skipping invalid schema file: ${schemaFileInfo.filePath}`);
|
|
11672
|
+
continue;
|
|
11673
|
+
}
|
|
11674
|
+
const schemaName = schemaFile.metadata.name;
|
|
11675
|
+
// Check if schema already exists in database
|
|
11676
|
+
const existingSchemas = await db
|
|
11677
|
+
.select()
|
|
11678
|
+
.from(schemas)
|
|
11679
|
+
.where(eq(schemas.name, schemaName))
|
|
11680
|
+
.limit(1);
|
|
11681
|
+
// Only migrate if it doesn't exist or if existing record doesn't have schemaFileId
|
|
11682
|
+
if (existingSchemas.length === 0 || !existingSchemas[0].schemaFileId) {
|
|
11683
|
+
// Add schema to database as published (isDraft = false)
|
|
11684
|
+
await addSchemaToDb({
|
|
11685
|
+
name: schemaName,
|
|
11686
|
+
version: schemaFile.version,
|
|
11687
|
+
createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
|
|
11688
|
+
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
11689
|
+
}, schemaFile.id, // schemaFileId
|
|
11690
|
+
JSON.stringify(schemaFile, null, 2), // schemaData
|
|
11691
|
+
false);
|
|
11692
|
+
migratedCount++;
|
|
11693
|
+
logger$4(`Migrated schema: ${schemaName} v${schemaFile.version}`);
|
|
11694
|
+
}
|
|
11695
|
+
else {
|
|
11696
|
+
logger$4(`Schema ${schemaName} already exists in database, skipping`);
|
|
11697
|
+
}
|
|
11698
|
+
}
|
|
11699
|
+
catch (error) {
|
|
11700
|
+
logger$4(`Error migrating schema file ${schemaFileInfo.filePath}:`, error);
|
|
11701
|
+
}
|
|
11702
|
+
}
|
|
11703
|
+
logger$4(`Migration complete: ${migratedCount} schemas migrated`);
|
|
11704
|
+
return migratedCount;
|
|
11705
|
+
}
|
|
11523
11706
|
/**
|
|
11524
11707
|
* Extract the schema name from a schemaId string
|
|
11525
11708
|
* @param schemaId - Schema ID in the format `${schemaName}-${schemaVersion}`
|
|
@@ -11539,13 +11722,18 @@ function getSchemaNameFromId(schemaId) {
|
|
|
11539
11722
|
var schema = /*#__PURE__*/Object.freeze({
|
|
11540
11723
|
__proto__: null,
|
|
11541
11724
|
createSchema: createSchema,
|
|
11725
|
+
deleteSchema: deleteSchema,
|
|
11726
|
+
filterLatestSchemas: filterLatestSchemas,
|
|
11727
|
+
findSchemaByName: findSchemaByName,
|
|
11542
11728
|
getLatestSchemaVersion: getLatestSchemaVersion,
|
|
11543
11729
|
getSchemaNameFromId: getSchemaNameFromId,
|
|
11544
11730
|
listCompleteSchemaFiles: listCompleteSchemaFiles,
|
|
11545
11731
|
listLatestSchemaFiles: listLatestSchemaFiles,
|
|
11546
11732
|
listSchemaFiles: listSchemaFiles,
|
|
11547
11733
|
loadAllSchemasFromDb: loadAllSchemasFromDb,
|
|
11548
|
-
|
|
11734
|
+
migrateFileSchemasToDb: migrateFileSchemasToDb,
|
|
11735
|
+
readSchema: readSchema,
|
|
11736
|
+
updateSchema: updateSchema
|
|
11549
11737
|
});
|
|
11550
11738
|
|
|
11551
11739
|
const { sha3_256 } = sha3;
|
|
@@ -11639,7 +11827,7 @@ function getRefValueType(prop) {
|
|
|
11639
11827
|
* @returns Promise that resolves when properties are found, or rejects if not found after max retries
|
|
11640
11828
|
*/
|
|
11641
11829
|
const verifyPropertiesPersisted = async (db, modelId, modelName, maxRetries = 10, retryDelay = 100) => {
|
|
11642
|
-
const _mod_17 = await import('./BasePathResolver-
|
|
11830
|
+
const _mod_17 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
11643
11831
|
const _ns_17 = _mod_17.M;
|
|
11644
11832
|
const modelSchemaMod = _ns_17;
|
|
11645
11833
|
const { properties: propertiesTable } = modelSchemaMod;
|
|
@@ -11987,7 +12175,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
11987
12175
|
// Check DB for existing schema by name+version (same as minimal path)
|
|
11988
12176
|
const db = BaseDb.getAppDb();
|
|
11989
12177
|
if (db) {
|
|
11990
|
-
const _mod_18 = await import('./BasePathResolver-
|
|
12178
|
+
const _mod_18 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
11991
12179
|
const _ns_18 = _mod_18.S;
|
|
11992
12180
|
const schemaSchemaMod = _ns_18;
|
|
11993
12181
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
@@ -12071,7 +12259,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
12071
12259
|
// For minimal imports: check DB for existing schema before creating new file
|
|
12072
12260
|
const db = BaseDb.getAppDb();
|
|
12073
12261
|
if (db) {
|
|
12074
|
-
const _mod_19 = await import('./BasePathResolver-
|
|
12262
|
+
const _mod_19 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12075
12263
|
const _ns_19 = _mod_19.S;
|
|
12076
12264
|
const schemaSchemaMod = _ns_19;
|
|
12077
12265
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
@@ -12252,7 +12440,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
12252
12440
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
12253
12441
|
};
|
|
12254
12442
|
// Use dynamic import to break circular dependency
|
|
12255
|
-
const dbMod = await import('./db-
|
|
12443
|
+
const dbMod = await import('./db-Bad8QKfZ.js');
|
|
12256
12444
|
const { addSchemaToDb, addModelsToDb } = dbMod;
|
|
12257
12445
|
// Try to add schema and models to database if database is available
|
|
12258
12446
|
try {
|
|
@@ -12272,11 +12460,11 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
12272
12460
|
});
|
|
12273
12461
|
// Verify expected models are linked (single attempt - addModelsToDb already confirmed)
|
|
12274
12462
|
const expectedModelNames = Object.keys(schemaFile.models || {});
|
|
12275
|
-
const _mod_20 = await import('./BasePathResolver-
|
|
12463
|
+
const _mod_20 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12276
12464
|
const _ns_20 = _mod_20.x;
|
|
12277
12465
|
const modelSchemaSchemaMod = _ns_20;
|
|
12278
12466
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
12279
|
-
const _mod_21 = await import('./BasePathResolver-
|
|
12467
|
+
const _mod_21 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12280
12468
|
const _ns_21 = _mod_21.M;
|
|
12281
12469
|
const modelSchemaMod = _ns_21;
|
|
12282
12470
|
const { models: modelsTable } = modelSchemaMod;
|
|
@@ -12479,7 +12667,7 @@ async function applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, prope
|
|
|
12479
12667
|
createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
|
|
12480
12668
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
12481
12669
|
};
|
|
12482
|
-
const dbMod = await import('./db-
|
|
12670
|
+
const dbMod = await import('./db-Bad8QKfZ.js');
|
|
12483
12671
|
const { addSchemaToDb, addModelsToDb } = dbMod;
|
|
12484
12672
|
const db = BaseDb.getAppDb();
|
|
12485
12673
|
if (!db) {
|
|
@@ -12637,11 +12825,11 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
12637
12825
|
if (db) {
|
|
12638
12826
|
const { schemaRecord } = await applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, propertyFileIds);
|
|
12639
12827
|
// Query the database to get model IDs that were just created
|
|
12640
|
-
const _mod_22 = await import('./BasePathResolver-
|
|
12828
|
+
const _mod_22 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12641
12829
|
const _ns_22 = _mod_22.x;
|
|
12642
12830
|
const modelSchemaSchemaMod = _ns_22;
|
|
12643
12831
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
12644
|
-
const _mod_23 = await import('./BasePathResolver-
|
|
12832
|
+
const _mod_23 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12645
12833
|
const _ns_23 = _mod_23.M;
|
|
12646
12834
|
const modelSchemaMod = _ns_23;
|
|
12647
12835
|
const { models: modelsTable } = modelSchemaMod;
|
|
@@ -12707,7 +12895,7 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
12707
12895
|
// After properties are created (file path), ensure schemaFile has the correct IDs from database
|
|
12708
12896
|
// Query the database to get the actual schemaFileId values that were used
|
|
12709
12897
|
// This ensures schemaData matches what's actually in the database
|
|
12710
|
-
const _mod_24 = await import('./BasePathResolver-
|
|
12898
|
+
const _mod_24 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12711
12899
|
const _ns_24 = _mod_24.M;
|
|
12712
12900
|
const modelSchemaMod2 = _ns_24;
|
|
12713
12901
|
const { properties: propertiesTable } = modelSchemaMod2;
|
|
@@ -12743,7 +12931,7 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
12743
12931
|
// This is important even if nothing changed, to ensure consistency
|
|
12744
12932
|
const updatedSchemaData = JSON.stringify(schemaFile, null, 2);
|
|
12745
12933
|
// Update the schema record in the database with current schemaData
|
|
12746
|
-
const _mod_25 = await import('./BasePathResolver-
|
|
12934
|
+
const _mod_25 = await import('./BasePathResolver-DWY_hb8w.js');
|
|
12747
12935
|
const _ns_25 = _mod_25.S;
|
|
12748
12936
|
const schemaSchemaMod = _ns_25;
|
|
12749
12937
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
@@ -13424,6 +13612,8 @@ const processSchemaFiles = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
13424
13612
|
|
|
13425
13613
|
/** Emitted by the client manager after `app_state.addresses` is written (post-`setAddresses`). */
|
|
13426
13614
|
const ADDRESSES_PERSISTED_EVENT = 'addresses.persisted';
|
|
13615
|
+
/** Emitted after hard-deleting local on-chain seed copies for publisher addresses. */
|
|
13616
|
+
const LOCAL_COPIES_REMOVED_EVENT = 'localCopies.removed';
|
|
13427
13617
|
function parseAddressesPersistedPayload(value) {
|
|
13428
13618
|
if (!value || typeof value !== 'object') {
|
|
13429
13619
|
return { owned: [], watched: [] };
|
|
@@ -13685,6 +13875,585 @@ const clientManagerMachine = setup({
|
|
|
13685
13875
|
},
|
|
13686
13876
|
});
|
|
13687
13877
|
|
|
13878
|
+
function msToUnixSeconds(ms) {
|
|
13879
|
+
if (ms == null || !Number.isFinite(ms))
|
|
13880
|
+
return 0;
|
|
13881
|
+
// Heuristic: values already in seconds are small; ms are large
|
|
13882
|
+
if (ms > 1e12)
|
|
13883
|
+
return Math.floor(ms / 1000);
|
|
13884
|
+
if (ms > 1e10)
|
|
13885
|
+
return Math.floor(ms / 1000);
|
|
13886
|
+
return Math.floor(ms);
|
|
13887
|
+
}
|
|
13888
|
+
function toSnakeCaseName(name) {
|
|
13889
|
+
return name
|
|
13890
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
13891
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
13892
|
+
.toLowerCase();
|
|
13893
|
+
}
|
|
13894
|
+
function parsePropertyValue(raw) {
|
|
13895
|
+
if (raw == null)
|
|
13896
|
+
return '';
|
|
13897
|
+
const t = raw.trim();
|
|
13898
|
+
if ((t.startsWith('[') && t.endsWith(']')) ||
|
|
13899
|
+
(t.startsWith('{') && t.endsWith('}'))) {
|
|
13900
|
+
try {
|
|
13901
|
+
return JSON.parse(t);
|
|
13902
|
+
}
|
|
13903
|
+
catch {
|
|
13904
|
+
return raw;
|
|
13905
|
+
}
|
|
13906
|
+
}
|
|
13907
|
+
return raw;
|
|
13908
|
+
}
|
|
13909
|
+
function attestationFromRaw(raw) {
|
|
13910
|
+
if (!raw || !raw.trim())
|
|
13911
|
+
return null;
|
|
13912
|
+
try {
|
|
13913
|
+
const parsed = JSON.parse(raw);
|
|
13914
|
+
if (parsed && typeof parsed.id === 'string')
|
|
13915
|
+
return parsed;
|
|
13916
|
+
}
|
|
13917
|
+
catch {
|
|
13918
|
+
// fall through
|
|
13919
|
+
}
|
|
13920
|
+
return null;
|
|
13921
|
+
}
|
|
13922
|
+
function seedRowToAttestation(row) {
|
|
13923
|
+
if (!row.uid || !isValidEasAttestationUid(row.uid))
|
|
13924
|
+
return null;
|
|
13925
|
+
const fromRaw = attestationFromRaw(row.attestationRaw);
|
|
13926
|
+
if (fromRaw) {
|
|
13927
|
+
const schemaName = row.schemaName ??
|
|
13928
|
+
fromRaw.schema?.schemaNames?.[0]?.name ??
|
|
13929
|
+
row.type ??
|
|
13930
|
+
'unknown';
|
|
13931
|
+
return {
|
|
13932
|
+
...fromRaw,
|
|
13933
|
+
id: row.uid,
|
|
13934
|
+
schema: {
|
|
13935
|
+
schemaNames: [{ name: schemaName }],
|
|
13936
|
+
},
|
|
13937
|
+
timeCreated: fromRaw.timeCreated ||
|
|
13938
|
+
msToUnixSeconds(row.attestationCreatedAt),
|
|
13939
|
+
attester: fromRaw.attester ?? row.publisher ?? undefined,
|
|
13940
|
+
schemaId: fromRaw.schemaId || row.schemaUid || '',
|
|
13941
|
+
};
|
|
13942
|
+
}
|
|
13943
|
+
const schemaName = row.schemaName ?? row.type ?? 'unknown';
|
|
13944
|
+
return {
|
|
13945
|
+
id: row.uid,
|
|
13946
|
+
decodedDataJson: '',
|
|
13947
|
+
refUID: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
13948
|
+
schemaId: row.schemaUid || '',
|
|
13949
|
+
timeCreated: msToUnixSeconds(row.attestationCreatedAt),
|
|
13950
|
+
attester: row.publisher ?? undefined,
|
|
13951
|
+
schema: { schemaNames: [{ name: schemaName }] },
|
|
13952
|
+
};
|
|
13953
|
+
}
|
|
13954
|
+
function versionRowToAttestation(row) {
|
|
13955
|
+
if (!row.uid || !isValidEasAttestationUid(row.uid))
|
|
13956
|
+
return null;
|
|
13957
|
+
if (!row.seedUid)
|
|
13958
|
+
return null;
|
|
13959
|
+
const fromRaw = attestationFromRaw(row.attestationRaw);
|
|
13960
|
+
if (fromRaw) {
|
|
13961
|
+
return {
|
|
13962
|
+
...fromRaw,
|
|
13963
|
+
id: row.uid,
|
|
13964
|
+
refUID: row.seedUid,
|
|
13965
|
+
timeCreated: fromRaw.timeCreated ||
|
|
13966
|
+
msToUnixSeconds(row.attestationCreatedAt),
|
|
13967
|
+
attester: fromRaw.attester ?? row.publisher ?? undefined,
|
|
13968
|
+
};
|
|
13969
|
+
}
|
|
13970
|
+
return {
|
|
13971
|
+
id: row.uid,
|
|
13972
|
+
decodedDataJson: '',
|
|
13973
|
+
refUID: row.seedUid,
|
|
13974
|
+
schemaId: '',
|
|
13975
|
+
timeCreated: msToUnixSeconds(row.attestationCreatedAt),
|
|
13976
|
+
attester: row.publisher ?? undefined,
|
|
13977
|
+
};
|
|
13978
|
+
}
|
|
13979
|
+
function metadataRowToAttestation(row) {
|
|
13980
|
+
if (!row.uid || !isValidEasAttestationUid(row.uid))
|
|
13981
|
+
return null;
|
|
13982
|
+
if (!row.versionUid)
|
|
13983
|
+
return null;
|
|
13984
|
+
const fromRaw = attestationFromRaw(row.attestationRaw);
|
|
13985
|
+
if (fromRaw) {
|
|
13986
|
+
return {
|
|
13987
|
+
...fromRaw,
|
|
13988
|
+
id: row.uid,
|
|
13989
|
+
refUID: row.versionUid,
|
|
13990
|
+
schemaId: fromRaw.schemaId || row.schemaUid || '',
|
|
13991
|
+
timeCreated: fromRaw.timeCreated ||
|
|
13992
|
+
msToUnixSeconds(row.attestationCreatedAt),
|
|
13993
|
+
attester: fromRaw.attester ?? row.publisher ?? undefined,
|
|
13994
|
+
};
|
|
13995
|
+
}
|
|
13996
|
+
const name = row.propertyName
|
|
13997
|
+
? toSnakeCaseName(row.propertyName)
|
|
13998
|
+
: 'unknown';
|
|
13999
|
+
const value = parsePropertyValue(row.propertyValue);
|
|
14000
|
+
const type = row.easDataType || 'string';
|
|
14001
|
+
return {
|
|
14002
|
+
id: row.uid,
|
|
14003
|
+
decodedDataJson: JSON.stringify([{ value: { name, value, type } }]),
|
|
14004
|
+
refUID: row.versionUid,
|
|
14005
|
+
schemaId: row.schemaUid || '',
|
|
14006
|
+
timeCreated: msToUnixSeconds(row.attestationCreatedAt),
|
|
14007
|
+
attester: row.publisher ?? undefined,
|
|
14008
|
+
};
|
|
14009
|
+
}
|
|
14010
|
+
async function resolveSchemaNameForSeedType(appDb, seedType) {
|
|
14011
|
+
if (!seedType)
|
|
14012
|
+
return null;
|
|
14013
|
+
const normalized = startCase(seedType);
|
|
14014
|
+
try {
|
|
14015
|
+
const schemaRows = await appDb
|
|
14016
|
+
.select({ schemaName: schemas.name })
|
|
14017
|
+
.from(models$1)
|
|
14018
|
+
.innerJoin(modelSchemas, eq(models$1.id, modelSchemas.modelId))
|
|
14019
|
+
.innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))
|
|
14020
|
+
.where(eq(models$1.name, normalized))
|
|
14021
|
+
.limit(1);
|
|
14022
|
+
if (schemaRows[0]?.schemaName)
|
|
14023
|
+
return schemaRows[0].schemaName;
|
|
14024
|
+
}
|
|
14025
|
+
catch {
|
|
14026
|
+
// ignore
|
|
14027
|
+
}
|
|
14028
|
+
return seedType;
|
|
14029
|
+
}
|
|
14030
|
+
function monthBoundsUnix(year, month) {
|
|
14031
|
+
const startDate = new Date(year, month - 1, 1);
|
|
14032
|
+
const endDate = new Date(year, month, 0, 23, 59, 59);
|
|
14033
|
+
const startTs = Math.floor(startDate.getTime() / 1000);
|
|
14034
|
+
const endTs = Math.floor(endDate.getTime() / 1000) + 1;
|
|
14035
|
+
return { startTs, endTs };
|
|
14036
|
+
}
|
|
14037
|
+
async function listPublishedSeedRows(schemaName, opts) {
|
|
14038
|
+
const appDb = BaseDb.getAppDb();
|
|
14039
|
+
if (!appDb)
|
|
14040
|
+
return [];
|
|
14041
|
+
const snakeType = schemaName.includes('_')
|
|
14042
|
+
? schemaName
|
|
14043
|
+
: schemaName.replace(/([A-Z])/g, (m, i) => i === 0 ? m.toLowerCase() : `_${m.toLowerCase()}`);
|
|
14044
|
+
// Prefer exact type match (EAS schema names are usually lowercase singular)
|
|
14045
|
+
const typeCandidates = Array.from(new Set([schemaName, schemaName.toLowerCase(), snakeType.toLowerCase()]));
|
|
14046
|
+
const rows = await appDb
|
|
14047
|
+
.select({
|
|
14048
|
+
uid: seeds.uid,
|
|
14049
|
+
schemaUid: seeds.schemaUid,
|
|
14050
|
+
type: seeds.type,
|
|
14051
|
+
publisher: seeds.publisher,
|
|
14052
|
+
attestationRaw: seeds.attestationRaw,
|
|
14053
|
+
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
14054
|
+
revokedAt: seeds.revokedAt,
|
|
14055
|
+
markedForDeletion: seeds._markedForDeletion,
|
|
14056
|
+
})
|
|
14057
|
+
.from(seeds)
|
|
14058
|
+
.where(and(inArray(seeds.type, typeCandidates), isNotNull(seeds.uid), or(isNull(seeds.revokedAt), eq(seeds.revokedAt, 0)), or(isNull(seeds._markedForDeletion), eq(seeds._markedForDeletion, 0))))
|
|
14059
|
+
.orderBy(desc(seeds.attestationCreatedAt));
|
|
14060
|
+
const out = [];
|
|
14061
|
+
for (const row of rows) {
|
|
14062
|
+
if (!row.uid || !isValidEasAttestationUid(row.uid))
|
|
14063
|
+
continue;
|
|
14064
|
+
// Must have at least one published version
|
|
14065
|
+
const versionRows = await appDb
|
|
14066
|
+
.select({
|
|
14067
|
+
uid: versions.uid,
|
|
14068
|
+
})
|
|
14069
|
+
.from(versions)
|
|
14070
|
+
.where(eq(versions.seedUid, row.uid))
|
|
14071
|
+
.orderBy(desc(versions.createdAt));
|
|
14072
|
+
const hasPublished = versionRows.some((v) => v.uid && isValidEasAttestationUid(v.uid));
|
|
14073
|
+
if (!hasPublished)
|
|
14074
|
+
continue;
|
|
14075
|
+
const schemaResolved = await resolveSchemaNameForSeedType(appDb, row.type);
|
|
14076
|
+
const att = seedRowToAttestation({
|
|
14077
|
+
...row,
|
|
14078
|
+
schemaName: schemaResolved === schemaName ? schemaName : (schemaResolved ?? schemaName),
|
|
14079
|
+
});
|
|
14080
|
+
if (!att)
|
|
14081
|
+
continue;
|
|
14082
|
+
// Force requested schema name so assembleSeeds filters correctly
|
|
14083
|
+
att.schema = { schemaNames: [{ name: schemaName }] };
|
|
14084
|
+
if (opts?.startTs != null || opts?.endTs != null) {
|
|
14085
|
+
const t = att.timeCreated;
|
|
14086
|
+
if (opts.startTs != null && t < opts.startTs)
|
|
14087
|
+
continue;
|
|
14088
|
+
if (opts.endTs != null && t >= opts.endTs)
|
|
14089
|
+
continue;
|
|
14090
|
+
}
|
|
14091
|
+
out.push(att);
|
|
14092
|
+
}
|
|
14093
|
+
return out;
|
|
14094
|
+
}
|
|
14095
|
+
/**
|
|
14096
|
+
* SDK local QueryDataSource: published Seeds/Versions/metadata from SQLite.
|
|
14097
|
+
*/
|
|
14098
|
+
function createLocalQueryDataSource() {
|
|
14099
|
+
return {
|
|
14100
|
+
kind: 'local',
|
|
14101
|
+
async getSeedByUid(seedUid) {
|
|
14102
|
+
const appDb = BaseDb.getAppDb();
|
|
14103
|
+
if (!appDb || !seedUid)
|
|
14104
|
+
return null;
|
|
14105
|
+
const rows = await appDb
|
|
14106
|
+
.select({
|
|
14107
|
+
uid: seeds.uid,
|
|
14108
|
+
schemaUid: seeds.schemaUid,
|
|
14109
|
+
type: seeds.type,
|
|
14110
|
+
publisher: seeds.publisher,
|
|
14111
|
+
attestationRaw: seeds.attestationRaw,
|
|
14112
|
+
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
14113
|
+
revokedAt: seeds.revokedAt,
|
|
14114
|
+
})
|
|
14115
|
+
.from(seeds)
|
|
14116
|
+
.where(eq(seeds.uid, seedUid))
|
|
14117
|
+
.limit(1);
|
|
14118
|
+
const row = rows[0];
|
|
14119
|
+
if (!row?.uid || !isValidEasAttestationUid(row.uid))
|
|
14120
|
+
return null;
|
|
14121
|
+
if (row.revokedAt != null && row.revokedAt !== 0)
|
|
14122
|
+
return null;
|
|
14123
|
+
const schemaName = await resolveSchemaNameForSeedType(appDb, row.type);
|
|
14124
|
+
return seedRowToAttestation({ ...row, schemaName });
|
|
14125
|
+
},
|
|
14126
|
+
async listSeedsBySchemaName(schemaName, opts) {
|
|
14127
|
+
const all = await listPublishedSeedRows(schemaName);
|
|
14128
|
+
return all.slice(opts.skip, opts.skip + opts.limit);
|
|
14129
|
+
},
|
|
14130
|
+
async listSeedsBySchemaNameForMonth(schemaName, year, month) {
|
|
14131
|
+
const { startTs, endTs } = monthBoundsUnix(year, month);
|
|
14132
|
+
return listPublishedSeedRows(schemaName, { startTs, endTs });
|
|
14133
|
+
},
|
|
14134
|
+
async getVersionsForSeed(seedUid) {
|
|
14135
|
+
return this.getVersionsForSeeds([seedUid]);
|
|
14136
|
+
},
|
|
14137
|
+
async getVersionsForSeeds(seedUids) {
|
|
14138
|
+
const appDb = BaseDb.getAppDb();
|
|
14139
|
+
if (!appDb || seedUids.length === 0)
|
|
14140
|
+
return [];
|
|
14141
|
+
const rows = await appDb
|
|
14142
|
+
.select({
|
|
14143
|
+
uid: versions.uid,
|
|
14144
|
+
seedUid: versions.seedUid,
|
|
14145
|
+
publisher: versions.publisher,
|
|
14146
|
+
attestationRaw: versions.attestationRaw,
|
|
14147
|
+
attestationCreatedAt: versions.attestationCreatedAt,
|
|
14148
|
+
})
|
|
14149
|
+
.from(versions)
|
|
14150
|
+
.where(inArray(versions.seedUid, seedUids));
|
|
14151
|
+
const out = [];
|
|
14152
|
+
for (const row of rows) {
|
|
14153
|
+
const att = versionRowToAttestation(row);
|
|
14154
|
+
if (att)
|
|
14155
|
+
out.push(att);
|
|
14156
|
+
}
|
|
14157
|
+
return out;
|
|
14158
|
+
},
|
|
14159
|
+
async getPropertiesForVersionUids(versionUids) {
|
|
14160
|
+
const appDb = BaseDb.getAppDb();
|
|
14161
|
+
if (!appDb || versionUids.length === 0)
|
|
14162
|
+
return [];
|
|
14163
|
+
const rows = await appDb
|
|
14164
|
+
.select({
|
|
14165
|
+
uid: metadata$1.uid,
|
|
14166
|
+
schemaUid: metadata$1.schemaUid,
|
|
14167
|
+
propertyName: metadata$1.propertyName,
|
|
14168
|
+
propertyValue: metadata$1.propertyValue,
|
|
14169
|
+
easDataType: metadata$1.easDataType,
|
|
14170
|
+
versionUid: metadata$1.versionUid,
|
|
14171
|
+
publisher: metadata$1.publisher,
|
|
14172
|
+
attestationRaw: metadata$1.attestationRaw,
|
|
14173
|
+
attestationCreatedAt: metadata$1.attestationCreatedAt,
|
|
14174
|
+
})
|
|
14175
|
+
.from(metadata$1)
|
|
14176
|
+
.where(inArray(metadata$1.versionUid, versionUids));
|
|
14177
|
+
const out = [];
|
|
14178
|
+
for (const row of rows) {
|
|
14179
|
+
const att = metadataRowToAttestation(row);
|
|
14180
|
+
if (att)
|
|
14181
|
+
out.push(att);
|
|
14182
|
+
}
|
|
14183
|
+
return out;
|
|
14184
|
+
},
|
|
14185
|
+
async getSeedsByUids(uids) {
|
|
14186
|
+
const appDb = BaseDb.getAppDb();
|
|
14187
|
+
if (!appDb || uids.length === 0)
|
|
14188
|
+
return [];
|
|
14189
|
+
const rows = await appDb
|
|
14190
|
+
.select({
|
|
14191
|
+
uid: seeds.uid,
|
|
14192
|
+
schemaUid: seeds.schemaUid,
|
|
14193
|
+
type: seeds.type,
|
|
14194
|
+
publisher: seeds.publisher,
|
|
14195
|
+
attestationRaw: seeds.attestationRaw,
|
|
14196
|
+
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
14197
|
+
revokedAt: seeds.revokedAt,
|
|
14198
|
+
})
|
|
14199
|
+
.from(seeds)
|
|
14200
|
+
.where(inArray(seeds.uid, uids));
|
|
14201
|
+
const out = [];
|
|
14202
|
+
for (const row of rows) {
|
|
14203
|
+
if (row.revokedAt != null && row.revokedAt !== 0)
|
|
14204
|
+
continue;
|
|
14205
|
+
const schemaName = await resolveSchemaNameForSeedType(appDb, row.type);
|
|
14206
|
+
const att = seedRowToAttestation({ ...row, schemaName });
|
|
14207
|
+
if (att)
|
|
14208
|
+
out.push(att);
|
|
14209
|
+
}
|
|
14210
|
+
return out;
|
|
14211
|
+
},
|
|
14212
|
+
async readStorageBody(ref) {
|
|
14213
|
+
try {
|
|
14214
|
+
if (ref.localPathHint) {
|
|
14215
|
+
const text = await BaseFileManager.readFileAsString(ref.localPathHint);
|
|
14216
|
+
if (text)
|
|
14217
|
+
return text;
|
|
14218
|
+
}
|
|
14219
|
+
// Common layout: html/{name}.html under filesDir
|
|
14220
|
+
if (typeof ref.value === 'string') {
|
|
14221
|
+
const v = ref.value.trim();
|
|
14222
|
+
// Absolute or relative file path already on disk
|
|
14223
|
+
if (v.includes('/') && !v.startsWith('http')) {
|
|
14224
|
+
try {
|
|
14225
|
+
const text = await BaseFileManager.readFileAsString(v);
|
|
14226
|
+
if (text)
|
|
14227
|
+
return text;
|
|
14228
|
+
}
|
|
14229
|
+
catch {
|
|
14230
|
+
// try under html/
|
|
14231
|
+
}
|
|
14232
|
+
}
|
|
14233
|
+
const htmlPath = BaseFileManager.getFilesPath('html', v.endsWith('.html') ? v : `${v}.html`);
|
|
14234
|
+
try {
|
|
14235
|
+
const text = await BaseFileManager.readFileAsString(htmlPath);
|
|
14236
|
+
if (text)
|
|
14237
|
+
return text;
|
|
14238
|
+
}
|
|
14239
|
+
catch {
|
|
14240
|
+
// fall through
|
|
14241
|
+
}
|
|
14242
|
+
}
|
|
14243
|
+
}
|
|
14244
|
+
catch {
|
|
14245
|
+
return null;
|
|
14246
|
+
}
|
|
14247
|
+
return null;
|
|
14248
|
+
},
|
|
14249
|
+
};
|
|
14250
|
+
}
|
|
14251
|
+
|
|
14252
|
+
let registered = false;
|
|
14253
|
+
/**
|
|
14254
|
+
* Register the SDK SQLite/files adapter with `@seedprotocol/query`.
|
|
14255
|
+
* Safe to call multiple times; re-registers with a fresh adapter instance.
|
|
14256
|
+
* No-op when the app DB is not ready yet (unless `force`).
|
|
14257
|
+
*/
|
|
14258
|
+
function registerSeedQueryLocalSource(options) {
|
|
14259
|
+
if (!options?.force && !BaseDb.isAppDbReady()) {
|
|
14260
|
+
return false;
|
|
14261
|
+
}
|
|
14262
|
+
try {
|
|
14263
|
+
registerLocalQuerySource(createLocalQueryDataSource());
|
|
14264
|
+
registered = true;
|
|
14265
|
+
return true;
|
|
14266
|
+
}
|
|
14267
|
+
catch (err) {
|
|
14268
|
+
console.warn('[sdk/query] registerSeedQueryLocalSource failed:', err);
|
|
14269
|
+
return false;
|
|
14270
|
+
}
|
|
14271
|
+
}
|
|
14272
|
+
/** Unregister local query source (tests / client unload). */
|
|
14273
|
+
function unregisterSeedQueryLocalSource() {
|
|
14274
|
+
clearLocalQuerySource();
|
|
14275
|
+
registered = false;
|
|
14276
|
+
}
|
|
14277
|
+
function isSeedQueryLocalSourceRegistered() {
|
|
14278
|
+
return registered;
|
|
14279
|
+
}
|
|
14280
|
+
/**
|
|
14281
|
+
* Thin published-JSON helper: `getSeed` via the local (or auto) query source.
|
|
14282
|
+
* Does not touch Item / drafts / liveQuery.
|
|
14283
|
+
*
|
|
14284
|
+
* Prefer this (or `@seedprotocol/query` `getSeed` / `queryBySchema`) for
|
|
14285
|
+
* canonical published Seed JSON. Use `getItemData` / Item for draft-head authoring.
|
|
14286
|
+
*/
|
|
14287
|
+
async function getPublishedSeedRecord(seedUid, options) {
|
|
14288
|
+
if (!registered) {
|
|
14289
|
+
registerSeedQueryLocalSource();
|
|
14290
|
+
}
|
|
14291
|
+
const source = options?.source ?? 'local';
|
|
14292
|
+
return getSeed(seedUid, { ...options, source });
|
|
14293
|
+
}
|
|
14294
|
+
|
|
14295
|
+
const READ_ONLY_ERROR = 'Item is read-only: you do not own this item';
|
|
14296
|
+
async function getSeedRowForItem(item) {
|
|
14297
|
+
const appDb = BaseDb.getAppDb();
|
|
14298
|
+
if (!appDb)
|
|
14299
|
+
return null;
|
|
14300
|
+
const conditions = [];
|
|
14301
|
+
if (item.seedLocalId)
|
|
14302
|
+
conditions.push(eq(seeds.localId, item.seedLocalId));
|
|
14303
|
+
if (item.seedUid)
|
|
14304
|
+
conditions.push(eq(seeds.uid, item.seedUid));
|
|
14305
|
+
if (conditions.length === 0)
|
|
14306
|
+
return null;
|
|
14307
|
+
const seedRows = await appDb
|
|
14308
|
+
.select({
|
|
14309
|
+
publisher: seeds.publisher,
|
|
14310
|
+
attestationRaw: seeds.attestationRaw,
|
|
14311
|
+
uid: seeds.uid,
|
|
14312
|
+
})
|
|
14313
|
+
.from(seeds)
|
|
14314
|
+
.where(conditions.length === 1 ? conditions[0] : or(...conditions))
|
|
14315
|
+
.limit(1);
|
|
14316
|
+
if (!seedRows || seedRows.length === 0)
|
|
14317
|
+
return null;
|
|
14318
|
+
return seedRows[0];
|
|
14319
|
+
}
|
|
14320
|
+
/** Resolve publisher from seed row: `publisher` column, else `attestationRaw.attester`. */
|
|
14321
|
+
function resolvePublisherFromSeedRow(row) {
|
|
14322
|
+
if (row.publisher)
|
|
14323
|
+
return row.publisher;
|
|
14324
|
+
if (row.attestationRaw) {
|
|
14325
|
+
try {
|
|
14326
|
+
const parsed = JSON.parse(row.attestationRaw);
|
|
14327
|
+
return parsed.attester ?? null;
|
|
14328
|
+
}
|
|
14329
|
+
catch {
|
|
14330
|
+
return null;
|
|
14331
|
+
}
|
|
14332
|
+
}
|
|
14333
|
+
return null;
|
|
14334
|
+
}
|
|
14335
|
+
/**
|
|
14336
|
+
* Checks if the current user owns the item (publisher is in owned addresses).
|
|
14337
|
+
* Locally created items (no publisher, no attestationRaw) are considered owned.
|
|
14338
|
+
* Includes getAdditionalSyncAddresses (e.g. `modularAccountModuleContract` when configured)
|
|
14339
|
+
* so ownership aligns with EAS sync when the publisher/attester matches those addresses.
|
|
14340
|
+
*/
|
|
14341
|
+
async function isItemOwned(item) {
|
|
14342
|
+
const row = await getSeedRowForItem(item);
|
|
14343
|
+
if (!row)
|
|
14344
|
+
return false;
|
|
14345
|
+
const publisher = resolvePublisherFromSeedRow(row);
|
|
14346
|
+
if (!publisher) {
|
|
14347
|
+
if (!row.uid && !row.attestationRaw) {
|
|
14348
|
+
return true;
|
|
14349
|
+
}
|
|
14350
|
+
return false;
|
|
14351
|
+
}
|
|
14352
|
+
let addressesToCheck = await getOwnedAddressesFromDb();
|
|
14353
|
+
const additionalGetter = getGetAdditionalSyncAddresses();
|
|
14354
|
+
if (additionalGetter) {
|
|
14355
|
+
const additional = await additionalGetter();
|
|
14356
|
+
if (additional?.length) {
|
|
14357
|
+
const seen = new Set(addressesToCheck.map((a) => a.toLowerCase()));
|
|
14358
|
+
for (const addr of additional) {
|
|
14359
|
+
if (addr && !seen.has(addr.toLowerCase())) {
|
|
14360
|
+
seen.add(addr.toLowerCase());
|
|
14361
|
+
addressesToCheck = [...addressesToCheck, addr];
|
|
14362
|
+
}
|
|
14363
|
+
}
|
|
14364
|
+
}
|
|
14365
|
+
}
|
|
14366
|
+
const ownedSet = new Set(addressesToCheck.map((a) => a.toLowerCase()));
|
|
14367
|
+
return ownedSet.has(publisher.toLowerCase());
|
|
14368
|
+
}
|
|
14369
|
+
/**
|
|
14370
|
+
* Throws if the item is not owned. Use before write operations (publish, save, destroy).
|
|
14371
|
+
*/
|
|
14372
|
+
async function assertItemOwned(item) {
|
|
14373
|
+
const owned = await isItemOwned(item);
|
|
14374
|
+
if (!owned) {
|
|
14375
|
+
throw new Error(READ_ONLY_ERROR);
|
|
14376
|
+
}
|
|
14377
|
+
}
|
|
14378
|
+
|
|
14379
|
+
var ownership = /*#__PURE__*/Object.freeze({
|
|
14380
|
+
__proto__: null,
|
|
14381
|
+
assertItemOwned: assertItemOwned,
|
|
14382
|
+
isItemOwned: isItemOwned,
|
|
14383
|
+
resolvePublisherFromSeedRow: resolvePublisherFromSeedRow
|
|
14384
|
+
});
|
|
14385
|
+
|
|
14386
|
+
const emptyResult = () => ({
|
|
14387
|
+
removedSeedLocalIds: [],
|
|
14388
|
+
removedSeedUids: [],
|
|
14389
|
+
});
|
|
14390
|
+
function normalizeAddresses(addresses) {
|
|
14391
|
+
return [
|
|
14392
|
+
...new Set(addresses
|
|
14393
|
+
.filter((a) => typeof a === 'string' && a.length > 0)
|
|
14394
|
+
.map((a) => a.toLowerCase())),
|
|
14395
|
+
];
|
|
14396
|
+
}
|
|
14397
|
+
/**
|
|
14398
|
+
* Find local on-chain seed copies for the given publisher addresses (no delete).
|
|
14399
|
+
* Drafts (no uid and no attestationRaw) are excluded.
|
|
14400
|
+
*/
|
|
14401
|
+
async function findLocalOnchainCopiesForAddresses(addresses) {
|
|
14402
|
+
const normalized = normalizeAddresses(addresses);
|
|
14403
|
+
if (normalized.length === 0) {
|
|
14404
|
+
return emptyResult();
|
|
14405
|
+
}
|
|
14406
|
+
const appDb = BaseDb.getAppDb();
|
|
14407
|
+
if (!appDb) {
|
|
14408
|
+
return emptyResult();
|
|
14409
|
+
}
|
|
14410
|
+
const addressSet = new Set(normalized);
|
|
14411
|
+
const candidateRows = (await appDb
|
|
14412
|
+
.select({
|
|
14413
|
+
localId: seeds.localId,
|
|
14414
|
+
uid: seeds.uid,
|
|
14415
|
+
publisher: seeds.publisher,
|
|
14416
|
+
attestationRaw: seeds.attestationRaw,
|
|
14417
|
+
})
|
|
14418
|
+
.from(seeds)
|
|
14419
|
+
.where(or(isNotNull(seeds.uid), isNotNull(seeds.attestationRaw))));
|
|
14420
|
+
const matched = candidateRows.filter((row) => {
|
|
14421
|
+
if (!row.localId)
|
|
14422
|
+
return false;
|
|
14423
|
+
const publisher = resolvePublisherFromSeedRow(row);
|
|
14424
|
+
return publisher != null && addressSet.has(publisher.toLowerCase());
|
|
14425
|
+
});
|
|
14426
|
+
return {
|
|
14427
|
+
removedSeedLocalIds: matched.map((r) => r.localId).filter(Boolean),
|
|
14428
|
+
removedSeedUids: matched
|
|
14429
|
+
.map((r) => r.uid)
|
|
14430
|
+
.filter((u) => typeof u === 'string' && u.length > 0),
|
|
14431
|
+
};
|
|
14432
|
+
}
|
|
14433
|
+
/**
|
|
14434
|
+
* Hard-delete the given seed local ids and related local rows (cascade).
|
|
14435
|
+
* Does not touch schemas, app_state, or chain.
|
|
14436
|
+
*/
|
|
14437
|
+
async function hardDeleteLocalSeedsByLocalIds(seedLocalIds) {
|
|
14438
|
+
if (seedLocalIds.length === 0)
|
|
14439
|
+
return;
|
|
14440
|
+
const appDb = BaseDb.getAppDb();
|
|
14441
|
+
if (!appDb)
|
|
14442
|
+
return;
|
|
14443
|
+
await appDb
|
|
14444
|
+
.delete(htmlEmbeddedImageCoPublish)
|
|
14445
|
+
.where(or(inArray(htmlEmbeddedImageCoPublish.parentSeedLocalId, seedLocalIds), inArray(htmlEmbeddedImageCoPublish.htmlSeedLocalId, seedLocalIds), inArray(htmlEmbeddedImageCoPublish.imageSeedLocalId, seedLocalIds)));
|
|
14446
|
+
await appDb
|
|
14447
|
+
.delete(arweaveL1FinalizeJobs)
|
|
14448
|
+
.where(inArray(arweaveL1FinalizeJobs.seedLocalId, seedLocalIds));
|
|
14449
|
+
await appDb
|
|
14450
|
+
.delete(publishProcesses)
|
|
14451
|
+
.where(inArray(publishProcesses.seedLocalId, seedLocalIds));
|
|
14452
|
+
await appDb.delete(metadata$1).where(inArray(metadata$1.seedLocalId, seedLocalIds));
|
|
14453
|
+
await appDb.delete(versions).where(inArray(versions.seedLocalId, seedLocalIds));
|
|
14454
|
+
await appDb.delete(seeds).where(inArray(seeds.localId, seedLocalIds));
|
|
14455
|
+
}
|
|
14456
|
+
|
|
13688
14457
|
const logger$1 = debug('seedSdk:client');
|
|
13689
14458
|
const clientManager = createActor(clientManagerMachine, {
|
|
13690
14459
|
input: {
|
|
@@ -13789,6 +14558,8 @@ const clientInstance = {
|
|
|
13789
14558
|
}
|
|
13790
14559
|
throw error;
|
|
13791
14560
|
}
|
|
14561
|
+
// Wire `@seedprotocol/query` local source once DB is ready
|
|
14562
|
+
registerSeedQueryLocalSource({ force: true });
|
|
13792
14563
|
},
|
|
13793
14564
|
setAddresses: async (addresses) => {
|
|
13794
14565
|
ensureInitialized();
|
|
@@ -13811,6 +14582,29 @@ const clientInstance = {
|
|
|
13811
14582
|
ensureInitialized();
|
|
13812
14583
|
return getWatchedAddressesFromDb();
|
|
13813
14584
|
},
|
|
14585
|
+
/**
|
|
14586
|
+
* Hard-delete local on-chain seed copies for the given publisher addresses.
|
|
14587
|
+
* Drafts (no uid / attestationRaw) are kept. Chain is untouched; reconnect can rehydrate via syncFromEas.
|
|
14588
|
+
*/
|
|
14589
|
+
removeLocalCopiesForAddresses: async (addresses) => {
|
|
14590
|
+
ensureInitialized();
|
|
14591
|
+
const list = Array.isArray(addresses) ? addresses : [];
|
|
14592
|
+
const matched = await findLocalOnchainCopiesForAddresses(list);
|
|
14593
|
+
const cacheIds = [
|
|
14594
|
+
...matched.removedSeedLocalIds,
|
|
14595
|
+
...matched.removedSeedUids,
|
|
14596
|
+
];
|
|
14597
|
+
if (cacheIds.length > 0) {
|
|
14598
|
+
Item.dropCachedInstancesForSeedIds(cacheIds);
|
|
14599
|
+
}
|
|
14600
|
+
await hardDeleteLocalSeedsByLocalIds(matched.removedSeedLocalIds);
|
|
14601
|
+
eventEmitter.emit(LOCAL_COPIES_REMOVED_EVENT, {
|
|
14602
|
+
addresses: list,
|
|
14603
|
+
removedSeedLocalIds: matched.removedSeedLocalIds,
|
|
14604
|
+
removedSeedUids: matched.removedSeedUids,
|
|
14605
|
+
});
|
|
14606
|
+
return matched;
|
|
14607
|
+
},
|
|
13814
14608
|
/**
|
|
13815
14609
|
* Syncs item attestations from EAS for the configured models and given addresses.
|
|
13816
14610
|
* Uses owned + watched addresses from DB when addresses are not provided.
|
|
@@ -13850,10 +14644,12 @@ const clientInstance = {
|
|
|
13850
14644
|
},
|
|
13851
14645
|
stop: () => {
|
|
13852
14646
|
ensureInitialized();
|
|
14647
|
+
unregisterSeedQueryLocalSource();
|
|
13853
14648
|
clientManager.stop();
|
|
13854
14649
|
},
|
|
13855
14650
|
unload: () => {
|
|
13856
14651
|
ensureInitialized();
|
|
14652
|
+
unregisterSeedQueryLocalSource();
|
|
13857
14653
|
clientManager.stop();
|
|
13858
14654
|
subscription.unsubscribe();
|
|
13859
14655
|
},
|
|
@@ -14036,7 +14832,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
|
|
|
14036
14832
|
// Lazy import cache for ModelProperty to avoid circular dependency
|
|
14037
14833
|
// Eagerly start loading to minimize delay on first access
|
|
14038
14834
|
let ModelPropertyClass = null;
|
|
14039
|
-
const modelPropertyImportPromise = import('./ModelProperty-
|
|
14835
|
+
const modelPropertyImportPromise = import('./ModelProperty-DGJf78CS.js')
|
|
14040
14836
|
.then(module => {
|
|
14041
14837
|
ModelPropertyClass = module.ModelProperty;
|
|
14042
14838
|
return ModelPropertyClass;
|
|
@@ -14053,7 +14849,7 @@ function getModelProperty() {
|
|
|
14053
14849
|
}
|
|
14054
14850
|
// Lazy import cache for Schema to avoid circular dependency
|
|
14055
14851
|
let SchemaClass = null;
|
|
14056
|
-
const schemaImportPromise = (async () => { const _mod_26 = await import('./Schema-
|
|
14852
|
+
const schemaImportPromise = (async () => { const _mod_26 = await import('./Schema-Drmce3q-.js'); return _mod_26.b; })()
|
|
14057
14853
|
.then(module => {
|
|
14058
14854
|
SchemaClass = module.Schema;
|
|
14059
14855
|
return SchemaClass;
|
|
@@ -15793,5 +16589,5 @@ var Model$1 = /*#__PURE__*/Object.freeze({
|
|
|
15793
16589
|
const TModelValues = Type.Record(Type.String(), Type.Any());
|
|
15794
16590
|
const TModelSchema = Type.Record(Type.String(), TProperty);
|
|
15795
16591
|
|
|
15796
|
-
export {
|
|
15797
|
-
//# sourceMappingURL=index
|
|
16592
|
+
export { registerSeedQueryLocalSource as $, compareMetadataRowsLatestFirst as A, ADDRESSES_PERSISTED_EVENT as B, ClientManager as C, createLocalQueryDataSource as D, createNewItem as E, createSchema as F, easSyncActor as G, getClient as H, Item as I, getGetPublisherForNewSeeds as J, getMetadataLatest as K, LOCAL_COPIES_REMOVED_EVENT as L, Model as M, getPublishedSeedRecord as N, getRevokeExecutor as O, getSchemaNameFromId as P, getUploadExecutor as Q, getVersionData$1 as R, isItemOwned as S, TModelSchema as T, isSeedQueryLocalSourceRegistered as U, listCompleteSchemaFiles as V, loadAllSchemasFromDb as W, mergeEasSyncRequestIntents as X, parseAddressesPersistedPayload as Y, propertyMachine as Z, readSchema as _, TModelValues as a, requestEasSyncFromAddressChange as a0, requestEasSyncFromEventBus as a1, requestEasSyncFromModelsInit as a2, sendEasSyncClientRequest as a3, setAdditionalSyncAddresses as a4, setGetPublisherForNewSeeds as a5, setRevokeExecutor as a6, setUploadExecutor as a7, startEasSyncActor as a8, unregisterSeedQueryLocalSource as a9, createModelsFromJson as aa, getLatestSchemaVersion as ab, createModelFromJson as ac, ConflictError as ad, unloadEntity as ae, clearDestroySubscriptions as af, setupEntityLiveQuery as ag, publishConfig as ah, generateId$1 as ai, model as aj, getPropertyData$1 as ak, Item$1 as al, schema as am, SEEDPROTOCOL_Seed_Protocol_v1 as an, Model$1 as ao, getItemData as b, getEasSchemaUidForModel as c, getLatestPublishedVersionRow as d, getEasSchemaForItemProperty as e, eventEmitter as f, getContentHash as g, generateId as h, getGetAdditionalSyncAddresses as i, ItemProperty as j, getRefValueType as k, importJsonSchema as l, modelPropertiesToObject as m, loadSchemaFromFile as n, readJsonImportFile as o, parseListPropertyValueFromStorage as p, syncSchemaFromSource as q, resolveStorageNameToSchemaName as r, scheduleBulkFilesDownloadFromEasSync as s, transformImportToSchemaFile as t, waitForEntityIdle as u, createReactiveProxy as v, writeProcessMachine as w, findEntity as x, forceRemoveFromCaches as y, runDestroyLifecycle as z };
|
|
16593
|
+
//# sourceMappingURL=index-B4In0GEO.js.map
|