@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
|
@@ -12,6 +12,7 @@ var pluralize = require('pluralize');
|
|
|
12
12
|
var typebox = require('@sinclair/typebox');
|
|
13
13
|
var nanoid = require('nanoid');
|
|
14
14
|
var nanoidDictionary = require('nanoid-dictionary');
|
|
15
|
+
var query = require('@seedprotocol/query');
|
|
15
16
|
var casing = require('drizzle-orm/casing');
|
|
16
17
|
var lodashEs = require('lodash-es');
|
|
17
18
|
var rxjs = require('rxjs');
|
|
@@ -24,7 +25,6 @@ var client = require('@libsql/client');
|
|
|
24
25
|
var libsql = require('drizzle-orm/libsql');
|
|
25
26
|
var migrator = require('drizzle-orm/libsql/migrator');
|
|
26
27
|
var yaml = require('js-yaml');
|
|
27
|
-
require('@seedprotocol/webpack');
|
|
28
28
|
var child_process = require('child_process');
|
|
29
29
|
var node$1 = require('@seedprotocol/arweave/node');
|
|
30
30
|
var node = require('@seedprotocol/eas/node');
|
|
@@ -988,21 +988,6 @@ const convertTxIdToImage = async (txId) => {
|
|
|
988
988
|
const imageBlob = new Blob([uint]);
|
|
989
989
|
return URL.createObjectURL(imageBlob);
|
|
990
990
|
};
|
|
991
|
-
const parseEasRelationPropertyName = (easPropertyName) => {
|
|
992
|
-
// Split the input string on the first underscore
|
|
993
|
-
const [singularProperty, modelName, idSegment] = easPropertyName.split('_');
|
|
994
|
-
// If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)
|
|
995
|
-
const isList = idSegment === 'ids';
|
|
996
|
-
// Create the final property name by pluralizing the singular part
|
|
997
|
-
const propertyName = singularProperty.endsWith('s')
|
|
998
|
-
? singularProperty
|
|
999
|
-
: singularProperty + 's';
|
|
1000
|
-
return {
|
|
1001
|
-
propertyName, // Plural form of the property name
|
|
1002
|
-
modelName, // Model name extracted from the second part
|
|
1003
|
-
isList, // True if the property is a list (e.g., 'ids' is present)
|
|
1004
|
-
};
|
|
1005
|
-
};
|
|
1006
991
|
|
|
1007
992
|
const logger$v = debug('seedSdk:model:actors:loadOrCreateModel');
|
|
1008
993
|
/**
|
|
@@ -1015,7 +1000,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
1015
1000
|
return;
|
|
1016
1001
|
}
|
|
1017
1002
|
try {
|
|
1018
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
1003
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); });
|
|
1019
1004
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1020
1005
|
if (!ModelProperty) {
|
|
1021
1006
|
logger$v('createPropertyInstances: ModelProperty not available from dynamic import');
|
|
@@ -1199,7 +1184,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
1199
1184
|
// Step 2: Fallback to Schema context (only if database doesn't have the model)
|
|
1200
1185
|
// This handles the case where model exists in schema file but not yet in database
|
|
1201
1186
|
try {
|
|
1202
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1187
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
1203
1188
|
const { Schema } = schemaMod;
|
|
1204
1189
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
1205
1190
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
@@ -1443,7 +1428,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
1443
1428
|
}
|
|
1444
1429
|
// Mark schema as draft when a new model is created so saveNewVersion() can persist it
|
|
1445
1430
|
try {
|
|
1446
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1431
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
1447
1432
|
const { Schema } = schemaMod;
|
|
1448
1433
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
1449
1434
|
schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
|
|
@@ -1487,10 +1472,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
1487
1472
|
const _validateModel = async () => {
|
|
1488
1473
|
try {
|
|
1489
1474
|
// Use dynamic imports to break circular dependencies
|
|
1490
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1475
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
|
|
1491
1476
|
const { SchemaValidationService } = validationServiceMod;
|
|
1492
1477
|
const validationService = new SchemaValidationService();
|
|
1493
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1478
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
1494
1479
|
const { Schema } = schemaMod;
|
|
1495
1480
|
// Validate model structure
|
|
1496
1481
|
const structureResult = validationService.validateModelStructure(context);
|
|
@@ -1600,7 +1585,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
1600
1585
|
return;
|
|
1601
1586
|
}
|
|
1602
1587
|
logger$t(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
|
|
1603
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
1588
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); });
|
|
1604
1589
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1605
1590
|
if (!ModelProperty) {
|
|
1606
1591
|
logger$t('ModelProperty not available from dynamic import');
|
|
@@ -1703,7 +1688,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1703
1688
|
const structureMsg = `[validateEntity] Validating model structure`;
|
|
1704
1689
|
logger$s(structureMsg);
|
|
1705
1690
|
// Use existing Model validation
|
|
1706
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1691
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
|
|
1707
1692
|
const { SchemaValidationService } = validationServiceMod;
|
|
1708
1693
|
const validationService = new SchemaValidationService();
|
|
1709
1694
|
// Validate model structure
|
|
@@ -1721,7 +1706,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1721
1706
|
if (entityInput.entityData.schemaName) {
|
|
1722
1707
|
try {
|
|
1723
1708
|
logger$s(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
|
|
1724
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1709
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
1725
1710
|
const { Schema } = schemaMod;
|
|
1726
1711
|
const schema = Schema.create(entityInput.entityData.schemaName, {
|
|
1727
1712
|
waitForReady: false,
|
|
@@ -1757,7 +1742,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1757
1742
|
}
|
|
1758
1743
|
else if (entityInput.entityType === 'modelProperty') {
|
|
1759
1744
|
// Use existing ModelProperty validation
|
|
1760
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1745
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
|
|
1761
1746
|
const { SchemaValidationService } = validationServiceMod;
|
|
1762
1747
|
const validationService = new SchemaValidationService();
|
|
1763
1748
|
// Validate property structure
|
|
@@ -1772,7 +1757,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1772
1757
|
// If schema name and model name provided, validate against schema
|
|
1773
1758
|
if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
|
|
1774
1759
|
try {
|
|
1775
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1760
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
1776
1761
|
const { Schema } = schemaMod;
|
|
1777
1762
|
const schema = Schema.create(entityInput.entityData._schemaName, {
|
|
1778
1763
|
waitForReady: false,
|
|
@@ -1801,7 +1786,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1801
1786
|
}
|
|
1802
1787
|
else if (entityInput.entityType === 'schema') {
|
|
1803
1788
|
// Schema validation - use existing validation
|
|
1804
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1789
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
|
|
1805
1790
|
const { SchemaValidationService } = validationServiceMod;
|
|
1806
1791
|
const validationService = new SchemaValidationService();
|
|
1807
1792
|
const schemaResult = validationService.validateSchema(entityInput.entityData);
|
|
@@ -3842,7 +3827,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
3842
3827
|
// initial write completes is not overwritten by the stale requestWrite payload.
|
|
3843
3828
|
let dataToWrite = input.entityData;
|
|
3844
3829
|
try {
|
|
3845
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
3830
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); });
|
|
3846
3831
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
3847
3832
|
if (ModelProperty && typeof ModelProperty.getById === 'function') {
|
|
3848
3833
|
const instance = ModelProperty.getById(input.entityId);
|
|
@@ -4222,7 +4207,7 @@ const modelMachine = xstate.setup({
|
|
|
4222
4207
|
// Create ModelProperty instances for any new property IDs
|
|
4223
4208
|
if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
|
|
4224
4209
|
// Import and create instances asynchronously (fire-and-forget)
|
|
4225
|
-
Promise.resolve().then(function () { return require('./ModelProperty-
|
|
4210
|
+
Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); }).then(({ ModelProperty }) => {
|
|
4226
4211
|
const createPromises = newPropertyIds.map(async (propertyFileId) => {
|
|
4227
4212
|
try {
|
|
4228
4213
|
const property = await ModelProperty.createById(propertyFileId);
|
|
@@ -5203,7 +5188,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
5203
5188
|
const schemaNameToTry = model$1?.schemaName;
|
|
5204
5189
|
if (schemaNameToTry) {
|
|
5205
5190
|
try {
|
|
5206
|
-
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-
|
|
5191
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
5207
5192
|
const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
|
|
5208
5193
|
const schemaContext = schemaInstance.getService().getSnapshot().context;
|
|
5209
5194
|
if (schemaContext.models?.[modelName]?.properties) {
|
|
@@ -5252,7 +5237,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
5252
5237
|
}
|
|
5253
5238
|
}
|
|
5254
5239
|
if (Object.keys(propertySchemas).length === 0) {
|
|
5255
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
5240
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
5256
5241
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
5257
5242
|
const KNOWN_MODEL_FALLBACKS = {
|
|
5258
5243
|
Post: {
|
|
@@ -5299,7 +5284,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
5299
5284
|
// Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
|
|
5300
5285
|
let propSchema = propertySchemas[propertyName];
|
|
5301
5286
|
if (!propSchema && isRefTypeFromMeta) {
|
|
5302
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
5287
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
5303
5288
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
5304
5289
|
propSchema = {
|
|
5305
5290
|
dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
|
|
@@ -5556,9 +5541,9 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
5556
5541
|
sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
|
|
5557
5542
|
return;
|
|
5558
5543
|
}
|
|
5559
|
-
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-
|
|
5544
|
+
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DMKnK2_R.js'); });
|
|
5560
5545
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
5561
|
-
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-
|
|
5546
|
+
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DSBLjMKl.js'); });
|
|
5562
5547
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
5563
5548
|
const uploads = await getPublishUploads(item);
|
|
5564
5549
|
let uploadedTransactions = [];
|
|
@@ -6072,6 +6057,14 @@ async function getLatestPublishedVersionRow(seedLocalId) {
|
|
|
6072
6057
|
}
|
|
6073
6058
|
|
|
6074
6059
|
const logger$l = debug('seedSdk:db:read:getItemData');
|
|
6060
|
+
/**
|
|
6061
|
+
* Assemble flat ItemData for Item / liveQuery / draft-head authoring.
|
|
6062
|
+
*
|
|
6063
|
+
* For **published chain JSON** (Seed → latest attested Version → properties),
|
|
6064
|
+
* prefer `getPublishedSeedRecord` from `@seedprotocol/sdk` or
|
|
6065
|
+
* `getSeed` / `queryBySchema` from `@seedprotocol/query`. This function remains
|
|
6066
|
+
* the correct path for local-head / draft-wins property selection used by Item.
|
|
6067
|
+
*/
|
|
6075
6068
|
const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
6076
6069
|
if (!seedLocalId && !seedUid) {
|
|
6077
6070
|
throw new Error('[db/queries] [getItem] no seedLocalId or seedUid');
|
|
@@ -6531,7 +6524,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
6531
6524
|
const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
|
|
6532
6525
|
const _resolveRelatedValue = async () => {
|
|
6533
6526
|
// Use dynamic import to break circular dependency
|
|
6534
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
6527
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
6535
6528
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
6536
6529
|
if (!propertyValue || !isRelation || populatedFromDb) {
|
|
6537
6530
|
return;
|
|
@@ -7393,7 +7386,7 @@ async function fetchHtmlViaRawAcrossGateways(txId) {
|
|
|
7393
7386
|
return undefined;
|
|
7394
7387
|
try {
|
|
7395
7388
|
const resolved = arweave.getResolvedSeedGatewayEndpoints();
|
|
7396
|
-
if (!resolved || resolved.activePath !== 'hyper-sidecar') {
|
|
7389
|
+
if (!resolved || (resolved.activePath !== 'hyper-sidecar' && resolved.activePath !== 'http-proxy')) {
|
|
7397
7390
|
const { ensureReadGatewaySelected } = await import('@seedprotocol/arweave');
|
|
7398
7391
|
await ensureReadGatewaySelected().catch(() => { });
|
|
7399
7392
|
}
|
|
@@ -7534,7 +7527,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
7534
7527
|
// to use dynamically imported ModelPropertyDataTypes
|
|
7535
7528
|
const _hydrateFromDb = async () => {
|
|
7536
7529
|
// Use dynamic import to break circular dependency
|
|
7537
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
7530
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
7538
7531
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
7539
7532
|
const appDb = BaseDb.getAppDb();
|
|
7540
7533
|
const whereClauses = [];
|
|
@@ -7897,7 +7890,7 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
7897
7890
|
};
|
|
7898
7891
|
// Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
|
|
7899
7892
|
try {
|
|
7900
|
-
const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-
|
|
7893
|
+
const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-D4IB0zBz.js'); });
|
|
7901
7894
|
let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName);
|
|
7902
7895
|
if (!schemaFromFile?.validation) {
|
|
7903
7896
|
// Fallback: get validation from schemaData in database (Schema context may not be loaded yet)
|
|
@@ -8362,9 +8355,9 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
|
|
|
8362
8355
|
}
|
|
8363
8356
|
const _analyzeInput = async () => {
|
|
8364
8357
|
// Use dynamic import to break circular dependency
|
|
8365
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
8358
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
8366
8359
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
8367
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
8360
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
|
|
8368
8361
|
let propertyName = propertyNameRaw;
|
|
8369
8362
|
if (!propertyName) {
|
|
8370
8363
|
throw new Error('propertyName is required');
|
|
@@ -8562,7 +8555,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
|
|
|
8562
8555
|
propertyRecordSchema?.validation &&
|
|
8563
8556
|
metadataValues.propertyValue != null &&
|
|
8564
8557
|
metadataValues.propertyValue !== '') {
|
|
8565
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
8558
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DVmOGZao.js'); });
|
|
8566
8559
|
const validationService = new SchemaValidationService();
|
|
8567
8560
|
const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, normalizeDataType(propertyRecordSchema.dataType), propertyRecordSchema.validation, propertyRecordSchema.refValueType
|
|
8568
8561
|
? normalizeDataType(String(propertyRecordSchema.refValueType))
|
|
@@ -9155,7 +9148,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
|
|
|
9155
9148
|
}
|
|
9156
9149
|
const _saveRelation = async () => {
|
|
9157
9150
|
// Use dynamic import to break circular dependency
|
|
9158
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
9151
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
9159
9152
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
9160
9153
|
if (!propertyNameRaw) {
|
|
9161
9154
|
throw new Error('propertyName is required');
|
|
@@ -10199,7 +10192,7 @@ class ItemProperty {
|
|
|
10199
10192
|
return;
|
|
10200
10193
|
}
|
|
10201
10194
|
// Use dynamic import to break circular dependency
|
|
10202
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
10195
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-DQggpLqI.js'); });
|
|
10203
10196
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
10204
10197
|
const { context } = snapshot;
|
|
10205
10198
|
const { propertyRecordSchema } = context;
|
|
@@ -11108,7 +11101,7 @@ class ItemProperty {
|
|
|
11108
11101
|
}
|
|
11109
11102
|
async save() {
|
|
11110
11103
|
const ctx = this._getSnapshotContext();
|
|
11111
|
-
const { assertItemOwned } = await Promise.resolve().then(function () { return
|
|
11104
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
11112
11105
|
await assertItemOwned({
|
|
11113
11106
|
seedLocalId: ctx?.seedLocalId ?? undefined,
|
|
11114
11107
|
seedUid: ctx?.seedUid ?? undefined,
|
|
@@ -11447,7 +11440,7 @@ class Item {
|
|
|
11447
11440
|
});
|
|
11448
11441
|
};
|
|
11449
11442
|
this.unpublish = async () => {
|
|
11450
|
-
const { assertItemOwned } = await Promise.resolve().then(function () { return
|
|
11443
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
11451
11444
|
const { getRevokeExecutor } = await Promise.resolve().then(function () { return publishConfig; });
|
|
11452
11445
|
await assertItemOwned(this);
|
|
11453
11446
|
const seedUid = this.seedUid;
|
|
@@ -11471,7 +11464,7 @@ class Item {
|
|
|
11471
11464
|
this._service.send({ type: 'updateContext', revokedAt });
|
|
11472
11465
|
};
|
|
11473
11466
|
this.publish = async () => {
|
|
11474
|
-
const { assertItemOwned } = await Promise.resolve().then(function () { return
|
|
11467
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
11475
11468
|
await assertItemOwned(this);
|
|
11476
11469
|
this._service.send({ type: 'startPublish' });
|
|
11477
11470
|
return new Promise((resolve, reject) => {
|
|
@@ -11507,12 +11500,12 @@ class Item {
|
|
|
11507
11500
|
};
|
|
11508
11501
|
this.getPublishUploads = async (options) => {
|
|
11509
11502
|
// Use dynamic import to break circular dependency
|
|
11510
|
-
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-
|
|
11503
|
+
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DMKnK2_R.js'); });
|
|
11511
11504
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
11512
11505
|
return await getPublishUploads(this, [], undefined, options);
|
|
11513
11506
|
};
|
|
11514
11507
|
this.getPublishPayload = async (uploadedTransactions, options) => {
|
|
11515
|
-
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-
|
|
11508
|
+
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DSBLjMKl.js'); });
|
|
11516
11509
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
11517
11510
|
return await getPublishPayload(this, uploadedTransactions, options);
|
|
11518
11511
|
};
|
|
@@ -12165,6 +12158,39 @@ class Item {
|
|
|
12165
12158
|
}
|
|
12166
12159
|
return null;
|
|
12167
12160
|
}
|
|
12161
|
+
/**
|
|
12162
|
+
* Drop cached Item instances for the given seed local ids / uids without soft-deleting DB rows.
|
|
12163
|
+
* Used by local purge (`removeLocalCopiesForAddresses`) before hard-deleting rows.
|
|
12164
|
+
*/
|
|
12165
|
+
static dropCachedInstancesForSeedIds(ids) {
|
|
12166
|
+
const uniqueIds = [
|
|
12167
|
+
...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0)),
|
|
12168
|
+
];
|
|
12169
|
+
const seenInstances = new Set();
|
|
12170
|
+
for (const id of uniqueIds) {
|
|
12171
|
+
const entry = this.findItemInstanceCacheEntryById(id);
|
|
12172
|
+
if (entry && !seenInstances.has(entry.instance)) {
|
|
12173
|
+
seenInstances.add(entry.instance);
|
|
12174
|
+
const instance = entry.instance;
|
|
12175
|
+
const cacheKeys = this.collectInstanceCacheKeysForInstance(instance);
|
|
12176
|
+
clearDestroySubscriptions(instance, {
|
|
12177
|
+
instanceState: itemInstanceState,
|
|
12178
|
+
onUnload: (inst) => inst._subscription?.unsubscribe(),
|
|
12179
|
+
});
|
|
12180
|
+
forceRemoveFromCaches(instance, {
|
|
12181
|
+
getCacheKeys: () => cacheKeys,
|
|
12182
|
+
caches: [Item.instanceCache],
|
|
12183
|
+
});
|
|
12184
|
+
try {
|
|
12185
|
+
instance._service.stop();
|
|
12186
|
+
}
|
|
12187
|
+
catch {
|
|
12188
|
+
// Service may already be stopped
|
|
12189
|
+
}
|
|
12190
|
+
}
|
|
12191
|
+
ItemProperty.clearInstanceCacheForItem(id);
|
|
12192
|
+
}
|
|
12193
|
+
}
|
|
12168
12194
|
/**
|
|
12169
12195
|
* Create Item instance by ID (queries database if not in cache)
|
|
12170
12196
|
* The ID can be either seedUid or seedLocalId
|
|
@@ -13006,7 +13032,7 @@ class Item {
|
|
|
13006
13032
|
* Destroy the item: soft delete in DB, remove from caches, clean up subscriptions, stop service.
|
|
13007
13033
|
*/
|
|
13008
13034
|
async destroy() {
|
|
13009
|
-
const { assertItemOwned } = await Promise.resolve().then(function () { return
|
|
13035
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return ownership; });
|
|
13010
13036
|
await assertItemOwned(this);
|
|
13011
13037
|
const context = this._getSnapshotContext();
|
|
13012
13038
|
const cacheKeys = Item.collectInstanceCacheKeysForInstance(this);
|
|
@@ -13162,7 +13188,7 @@ const runEasSync = xstate.fromPromise(async ({ input, }) => {
|
|
|
13162
13188
|
requestPayload: input.requestPayload,
|
|
13163
13189
|
persistedSnapshot: input.runningSnapshot,
|
|
13164
13190
|
});
|
|
13165
|
-
const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-
|
|
13191
|
+
const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-BYvFJc7N.js'); });
|
|
13166
13192
|
try {
|
|
13167
13193
|
await runSyncFromEas(toRunSyncArg(input.options));
|
|
13168
13194
|
await finalizeEasSyncProcessRow(rowId, {
|
|
@@ -13577,6 +13603,7 @@ const platformClassesInit = xstate.fromCallback(({ sendBack, input: { context, e
|
|
|
13577
13603
|
gatewayHyperKey: resolvedGateway.gatewayHyperKey,
|
|
13578
13604
|
gatewaySidecarHost: gatewayConfig.hyper?.localSidecarHost,
|
|
13579
13605
|
gatewaySidecarPort: gatewayConfig.hyper?.localSidecarPort,
|
|
13606
|
+
gatewayProxyBaseUrl: resolvedGateway.proxyBaseUrl ?? gatewayConfig.proxyBaseUrl,
|
|
13580
13607
|
addresses: normalizedAddresses.owned,
|
|
13581
13608
|
ownedAddresses: normalizedAddresses.owned,
|
|
13582
13609
|
watchedAddresses: normalizedAddresses.watched,
|
|
@@ -13586,7 +13613,7 @@ const platformClassesInit = xstate.fromCallback(({ sendBack, input: { context, e
|
|
|
13586
13613
|
schema,
|
|
13587
13614
|
syncFromEasOnAddressChange: options.syncFromEasOnAddressChange ?? true,
|
|
13588
13615
|
} });
|
|
13589
|
-
if (resolvedGateway.activePath !== 'hyper-sidecar') {
|
|
13616
|
+
if (resolvedGateway.activePath !== 'hyper-sidecar' && resolvedGateway.activePath !== 'http-proxy') {
|
|
13590
13617
|
void arweave.ensureReadGatewaySelected().catch(() => {
|
|
13591
13618
|
/* non-blocking warm-up for read gateway probe */
|
|
13592
13619
|
});
|
|
@@ -13925,7 +13952,7 @@ const addModelsToDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
13925
13952
|
const logger$7 = debug('seedSdk:client:actors:saveConfig');
|
|
13926
13953
|
const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
13927
13954
|
logger$7('saveConfig starting');
|
|
13928
|
-
const { endpoints, addresses, ownedAddresses, watchedAddresses, arweaveDomain, uploadApiBaseUrl, gatewayTransport, gatewayHyperKey, gatewaySidecarHost, gatewaySidecarPort, } = context;
|
|
13955
|
+
const { endpoints, addresses, ownedAddresses, watchedAddresses, arweaveDomain, uploadApiBaseUrl, gatewayTransport, gatewayHyperKey, gatewaySidecarHost, gatewaySidecarPort, gatewayProxyBaseUrl, } = context;
|
|
13929
13956
|
// Validate endpoints - required for proper initialization
|
|
13930
13957
|
// If endpoints are missing or invalid, initialization should fail
|
|
13931
13958
|
if (!endpoints || !endpoints.filePaths || !endpoints.files) {
|
|
@@ -14005,6 +14032,7 @@ const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
14005
14032
|
if (gatewaySidecarPort != null) {
|
|
14006
14033
|
await persistKey('gatewaySidecarPort', String(gatewaySidecarPort));
|
|
14007
14034
|
}
|
|
14035
|
+
await persistKey('gatewayProxyBaseUrl', gatewayProxyBaseUrl);
|
|
14008
14036
|
}
|
|
14009
14037
|
catch (error) {
|
|
14010
14038
|
logger$7('[internal/actors] [saveConfig] Error saving config:', error);
|
|
@@ -14036,6 +14064,140 @@ const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
14036
14064
|
});
|
|
14037
14065
|
|
|
14038
14066
|
const logger$6 = debug('seedSdk:helpers:schema');
|
|
14067
|
+
/**
|
|
14068
|
+
* Sanitize a schema name to be filesystem-safe
|
|
14069
|
+
* Replaces all special characters (except alphanumeric, hyphens, underscores) with underscores
|
|
14070
|
+
* Converts spaces to underscores
|
|
14071
|
+
* Removes leading/trailing underscores
|
|
14072
|
+
*
|
|
14073
|
+
* @param name - Schema name to sanitize
|
|
14074
|
+
* @returns Sanitized name safe for use in filenames
|
|
14075
|
+
*/
|
|
14076
|
+
const sanitizeSchemaName$1 = (name) => {
|
|
14077
|
+
return name
|
|
14078
|
+
.replace(/[^a-zA-Z0-9\s_-]/g, '_') // Replace special chars (except spaces, hyphens, underscores) with underscore
|
|
14079
|
+
.replace(/\s+/g, '_') // Convert spaces to underscores
|
|
14080
|
+
.replace(/^_+|_+$/g, '') // Remove leading/trailing underscores
|
|
14081
|
+
.replace(/_+/g, '_'); // Collapse multiple underscores to single
|
|
14082
|
+
};
|
|
14083
|
+
/**
|
|
14084
|
+
* Generate filename for a schema
|
|
14085
|
+
* Format: {schemaFileId}_{schemaName}_v{version}.json
|
|
14086
|
+
*
|
|
14087
|
+
* The ID-first format ensures all files for a schema group together when sorted alphabetically.
|
|
14088
|
+
*
|
|
14089
|
+
* @param name - Schema name
|
|
14090
|
+
* @param version - Schema version
|
|
14091
|
+
* @param schemaFileId - Schema file ID (required)
|
|
14092
|
+
*/
|
|
14093
|
+
const getSchemaFilename = (name, version, schemaFileId) => {
|
|
14094
|
+
const sanitizedName = sanitizeSchemaName$1(name);
|
|
14095
|
+
return `${schemaFileId}_${sanitizedName}_v${version}.json`;
|
|
14096
|
+
};
|
|
14097
|
+
/**
|
|
14098
|
+
* Get the full file path for a schema
|
|
14099
|
+
* Format: {schemaFileId}_{schemaName}_v{version}.json
|
|
14100
|
+
*
|
|
14101
|
+
* The ID-first format ensures all files for a schema group together when sorted alphabetically.
|
|
14102
|
+
*
|
|
14103
|
+
* @param name - Schema name
|
|
14104
|
+
* @param version - Schema version
|
|
14105
|
+
* @param schemaFileId - Schema file ID (required)
|
|
14106
|
+
*/
|
|
14107
|
+
const getSchemaFilePath$1 = (name, version, schemaFileId) => {
|
|
14108
|
+
const path = BaseFileManager.getPathModule();
|
|
14109
|
+
const filename = getSchemaFilename(name, version, schemaFileId);
|
|
14110
|
+
const workingDir = BaseFileManager.getWorkingDir();
|
|
14111
|
+
return path.join(workingDir, filename);
|
|
14112
|
+
};
|
|
14113
|
+
/**
|
|
14114
|
+
* Create a new schema file
|
|
14115
|
+
* @param schema - The schema object to save
|
|
14116
|
+
* @param schemaFileId - Schema file ID (required)
|
|
14117
|
+
* @throws Error if schema already exists or if workingDir is invalid
|
|
14118
|
+
*/
|
|
14119
|
+
const createSchema = async (schema, schemaFileId) => {
|
|
14120
|
+
if (!schema.name || !schema.version) {
|
|
14121
|
+
throw new Error('Schema must have a name and version');
|
|
14122
|
+
}
|
|
14123
|
+
const filePath = getSchemaFilePath$1(schema.name, schema.version, schemaFileId);
|
|
14124
|
+
// Check if schema already exists
|
|
14125
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
14126
|
+
if (exists) {
|
|
14127
|
+
throw new Error(`Schema ${schema.name} v${schema.version} already exists`);
|
|
14128
|
+
}
|
|
14129
|
+
// Ensure working directory exists
|
|
14130
|
+
const workingDir = BaseFileManager.getWorkingDir();
|
|
14131
|
+
await BaseFileManager.createDirIfNotExists(workingDir);
|
|
14132
|
+
// Write schema to file
|
|
14133
|
+
const content = JSON.stringify(schema, null, 2);
|
|
14134
|
+
await BaseFileManager.saveFile(filePath, content);
|
|
14135
|
+
};
|
|
14136
|
+
/**
|
|
14137
|
+
* Read a schema file by name and version
|
|
14138
|
+
* @param name - The name of the schema
|
|
14139
|
+
* @param version - The version of the schema
|
|
14140
|
+
* @param schemaFileId - Schema file ID (required)
|
|
14141
|
+
* @returns The schema object, or null if not found
|
|
14142
|
+
*/
|
|
14143
|
+
const readSchema = async (name, version, schemaFileId) => {
|
|
14144
|
+
const filePath = getSchemaFilePath$1(name, version, schemaFileId);
|
|
14145
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
14146
|
+
if (!exists) {
|
|
14147
|
+
return null;
|
|
14148
|
+
}
|
|
14149
|
+
try {
|
|
14150
|
+
const content = await BaseFileManager.readFileAsString(filePath);
|
|
14151
|
+
return JSON.parse(content);
|
|
14152
|
+
}
|
|
14153
|
+
catch (error) {
|
|
14154
|
+
throw new Error(`Failed to read schema ${name} v${version}: ${error instanceof Error ? error.message : String(error)}`);
|
|
14155
|
+
}
|
|
14156
|
+
};
|
|
14157
|
+
/**
|
|
14158
|
+
* Update an existing schema file
|
|
14159
|
+
* @param schema - The updated schema object (must have same name and version as existing)
|
|
14160
|
+
* @param schemaFileId - Schema file ID (required)
|
|
14161
|
+
* @throws Error if schema doesn't exist
|
|
14162
|
+
*/
|
|
14163
|
+
async function updateSchema(schema, schemaFileId) {
|
|
14164
|
+
if (!schema.name || !schema.version) {
|
|
14165
|
+
throw new Error('Schema must have a name and version');
|
|
14166
|
+
}
|
|
14167
|
+
const filePath = getSchemaFilePath$1(schema.name, schema.version, schemaFileId);
|
|
14168
|
+
// Check if schema exists
|
|
14169
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
14170
|
+
if (!exists) {
|
|
14171
|
+
throw new Error(`Schema ${schema.name} v${schema.version} does not exist`);
|
|
14172
|
+
}
|
|
14173
|
+
// Write updated schema to file
|
|
14174
|
+
const content = JSON.stringify(schema, null, 2);
|
|
14175
|
+
await BaseFileManager.saveFile(filePath, content);
|
|
14176
|
+
}
|
|
14177
|
+
/**
|
|
14178
|
+
* Delete a schema file
|
|
14179
|
+
* @param name - The name of the schema
|
|
14180
|
+
* @param version - The version of the schema
|
|
14181
|
+
* @param schemaFileId - Schema file ID (required)
|
|
14182
|
+
* @throws Error if schema doesn't exist
|
|
14183
|
+
*/
|
|
14184
|
+
async function deleteSchema(name, version, schemaFileId) {
|
|
14185
|
+
const filePath = getSchemaFilePath$1(name, version, schemaFileId);
|
|
14186
|
+
// Check if schema exists
|
|
14187
|
+
const exists = await BaseFileManager.pathExists(filePath);
|
|
14188
|
+
if (!exists) {
|
|
14189
|
+
throw new Error(`Schema ${name} v${version} does not exist`);
|
|
14190
|
+
}
|
|
14191
|
+
// Delete the file
|
|
14192
|
+
const fs = await BaseFileManager.getFs();
|
|
14193
|
+
BaseFileManager.getPathModule();
|
|
14194
|
+
try {
|
|
14195
|
+
await fs.promises.unlink(filePath);
|
|
14196
|
+
}
|
|
14197
|
+
catch (error) {
|
|
14198
|
+
throw new Error(`Failed to delete schema ${name} v${version}: ${error instanceof Error ? error.message : String(error)}`);
|
|
14199
|
+
}
|
|
14200
|
+
}
|
|
14039
14201
|
/**
|
|
14040
14202
|
* List all schema files in the working directory
|
|
14041
14203
|
* Only returns files that are NOT already complete schema files (i.e., files without $schema field)
|
|
@@ -14146,6 +14308,24 @@ async function listCompleteSchemaFiles() {
|
|
|
14146
14308
|
throw new Error(`Failed to list complete schemas: ${error instanceof Error ? error.message : String(error)}`);
|
|
14147
14309
|
}
|
|
14148
14310
|
}
|
|
14311
|
+
/**
|
|
14312
|
+
* Find a schema by name (returns the latest version if multiple versions exist)
|
|
14313
|
+
* @param name - The name of the schema
|
|
14314
|
+
* @returns The schema with the highest version, or null if not found
|
|
14315
|
+
*/
|
|
14316
|
+
async function findSchemaByName(name) {
|
|
14317
|
+
const schemas = await listCompleteSchemaFiles();
|
|
14318
|
+
const matchingSchemas = schemas.filter((s) => s.name === name);
|
|
14319
|
+
if (matchingSchemas.length === 0) {
|
|
14320
|
+
return null;
|
|
14321
|
+
}
|
|
14322
|
+
// Find the schema with the highest version
|
|
14323
|
+
const latest = matchingSchemas.reduce((prev, current) => current.version > prev.version ? current : prev);
|
|
14324
|
+
if (!latest.schemaFileId) {
|
|
14325
|
+
throw new Error(`Schema ${latest.name} v${latest.version} is missing schemaFileId`);
|
|
14326
|
+
}
|
|
14327
|
+
return readSchema(latest.name, latest.version, latest.schemaFileId);
|
|
14328
|
+
}
|
|
14149
14329
|
/**
|
|
14150
14330
|
* Get the latest version number for a schema by name
|
|
14151
14331
|
* Only considers complete schema files (with $schema field)
|
|
@@ -14178,6 +14358,27 @@ async function listLatestSchemaFiles() {
|
|
|
14178
14358
|
}
|
|
14179
14359
|
return Array.from(schemaMap.values());
|
|
14180
14360
|
}
|
|
14361
|
+
/**
|
|
14362
|
+
* Filter an array of schemas to only include the latest version for each schema name
|
|
14363
|
+
* Works with any object that has a name (via metadata.name or name property) and a version property
|
|
14364
|
+
* @param schemas - Array of schema objects
|
|
14365
|
+
* @returns Array containing only the latest version of each schema
|
|
14366
|
+
*/
|
|
14367
|
+
function filterLatestSchemas(schemas) {
|
|
14368
|
+
// Group by schema name and keep only the latest version of each
|
|
14369
|
+
const schemaMap = new Map();
|
|
14370
|
+
for (const schema of schemas) {
|
|
14371
|
+
const schemaName = schema.metadata?.name || schema.name;
|
|
14372
|
+
if (!schemaName) {
|
|
14373
|
+
continue; // Skip schemas without a name
|
|
14374
|
+
}
|
|
14375
|
+
const existing = schemaMap.get(schemaName);
|
|
14376
|
+
if (!existing || schema.version > existing.version) {
|
|
14377
|
+
schemaMap.set(schemaName, schema);
|
|
14378
|
+
}
|
|
14379
|
+
}
|
|
14380
|
+
return Array.from(schemaMap.values());
|
|
14381
|
+
}
|
|
14181
14382
|
/**
|
|
14182
14383
|
* Unified schema loading function that queries database first, then merges with files
|
|
14183
14384
|
* Returns all schemas with their draft status and source information
|
|
@@ -14371,14 +14572,93 @@ async function loadAllSchemasFromDb() {
|
|
|
14371
14572
|
}
|
|
14372
14573
|
return result;
|
|
14373
14574
|
}
|
|
14575
|
+
/**
|
|
14576
|
+
* Migration helper: Migrate existing file-based schemas to the database
|
|
14577
|
+
* This function should be called once to migrate existing schema files to the new database-first approach
|
|
14578
|
+
* All existing schemas will be marked as published (isDraft = false) since they already exist in files
|
|
14579
|
+
* @returns Number of schemas migrated
|
|
14580
|
+
*/
|
|
14581
|
+
async function migrateFileSchemasToDb() {
|
|
14582
|
+
const db = BaseDb.getAppDb();
|
|
14583
|
+
if (!db) {
|
|
14584
|
+
throw new Error('Database not found');
|
|
14585
|
+
}
|
|
14586
|
+
logger$6('Starting migration of file-based schemas to database');
|
|
14587
|
+
// Get all complete schema files
|
|
14588
|
+
const completeSchemas = await listCompleteSchemaFiles();
|
|
14589
|
+
let migratedCount = 0;
|
|
14590
|
+
for (const schemaFileInfo of completeSchemas) {
|
|
14591
|
+
try {
|
|
14592
|
+
// Read the schema file
|
|
14593
|
+
const content = await BaseFileManager.readFileAsString(schemaFileInfo.filePath);
|
|
14594
|
+
const schemaFile = JSON.parse(content);
|
|
14595
|
+
if (!schemaFile.$schema || !schemaFile.metadata?.name) {
|
|
14596
|
+
logger$6(`Skipping invalid schema file: ${schemaFileInfo.filePath}`);
|
|
14597
|
+
continue;
|
|
14598
|
+
}
|
|
14599
|
+
const schemaName = schemaFile.metadata.name;
|
|
14600
|
+
// Check if schema already exists in database
|
|
14601
|
+
const existingSchemas = await db
|
|
14602
|
+
.select()
|
|
14603
|
+
.from(schemas)
|
|
14604
|
+
.where(drizzleOrm.eq(schemas.name, schemaName))
|
|
14605
|
+
.limit(1);
|
|
14606
|
+
// Only migrate if it doesn't exist or if existing record doesn't have schemaFileId
|
|
14607
|
+
if (existingSchemas.length === 0 || !existingSchemas[0].schemaFileId) {
|
|
14608
|
+
// Add schema to database as published (isDraft = false)
|
|
14609
|
+
await addSchemaToDb({
|
|
14610
|
+
name: schemaName,
|
|
14611
|
+
version: schemaFile.version,
|
|
14612
|
+
createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
|
|
14613
|
+
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
14614
|
+
}, schemaFile.id, // schemaFileId
|
|
14615
|
+
JSON.stringify(schemaFile, null, 2), // schemaData
|
|
14616
|
+
false);
|
|
14617
|
+
migratedCount++;
|
|
14618
|
+
logger$6(`Migrated schema: ${schemaName} v${schemaFile.version}`);
|
|
14619
|
+
}
|
|
14620
|
+
else {
|
|
14621
|
+
logger$6(`Schema ${schemaName} already exists in database, skipping`);
|
|
14622
|
+
}
|
|
14623
|
+
}
|
|
14624
|
+
catch (error) {
|
|
14625
|
+
logger$6(`Error migrating schema file ${schemaFileInfo.filePath}:`, error);
|
|
14626
|
+
}
|
|
14627
|
+
}
|
|
14628
|
+
logger$6(`Migration complete: ${migratedCount} schemas migrated`);
|
|
14629
|
+
return migratedCount;
|
|
14630
|
+
}
|
|
14631
|
+
/**
|
|
14632
|
+
* Extract the schema name from a schemaId string
|
|
14633
|
+
* @param schemaId - Schema ID in the format `${schemaName}-${schemaVersion}`
|
|
14634
|
+
* @returns The schema name, or null if the format is invalid
|
|
14635
|
+
*/
|
|
14636
|
+
function getSchemaNameFromId(schemaId) {
|
|
14637
|
+
if (!schemaId) {
|
|
14638
|
+
return null;
|
|
14639
|
+
}
|
|
14640
|
+
const lastDashIndex = schemaId.lastIndexOf('-');
|
|
14641
|
+
if (lastDashIndex === -1 || lastDashIndex === 0 || lastDashIndex === schemaId.length - 1) {
|
|
14642
|
+
return null;
|
|
14643
|
+
}
|
|
14644
|
+
return schemaId.substring(0, lastDashIndex);
|
|
14645
|
+
}
|
|
14374
14646
|
|
|
14375
14647
|
var schema = /*#__PURE__*/Object.freeze({
|
|
14376
14648
|
__proto__: null,
|
|
14649
|
+
createSchema: createSchema,
|
|
14650
|
+
deleteSchema: deleteSchema,
|
|
14651
|
+
filterLatestSchemas: filterLatestSchemas,
|
|
14652
|
+
findSchemaByName: findSchemaByName,
|
|
14377
14653
|
getLatestSchemaVersion: getLatestSchemaVersion,
|
|
14654
|
+
getSchemaNameFromId: getSchemaNameFromId,
|
|
14378
14655
|
listCompleteSchemaFiles: listCompleteSchemaFiles,
|
|
14379
14656
|
listLatestSchemaFiles: listLatestSchemaFiles,
|
|
14380
14657
|
listSchemaFiles: listSchemaFiles,
|
|
14381
|
-
loadAllSchemasFromDb: loadAllSchemasFromDb
|
|
14658
|
+
loadAllSchemasFromDb: loadAllSchemasFromDb,
|
|
14659
|
+
migrateFileSchemasToDb: migrateFileSchemasToDb,
|
|
14660
|
+
readSchema: readSchema,
|
|
14661
|
+
updateSchema: updateSchema
|
|
14382
14662
|
});
|
|
14383
14663
|
|
|
14384
14664
|
const { sha3_256 } = sha3__namespace;
|
|
@@ -16239,6 +16519,8 @@ const processSchemaFiles = xstate.fromCallback(({ sendBack, input: { context } }
|
|
|
16239
16519
|
|
|
16240
16520
|
/** Emitted by the client manager after `app_state.addresses` is written (post-`setAddresses`). */
|
|
16241
16521
|
const ADDRESSES_PERSISTED_EVENT = 'addresses.persisted';
|
|
16522
|
+
/** Emitted after hard-deleting local on-chain seed copies for publisher addresses. */
|
|
16523
|
+
const LOCAL_COPIES_REMOVED_EVENT = 'localCopies.removed';
|
|
16242
16524
|
function parseAddressesPersistedPayload(value) {
|
|
16243
16525
|
if (!value || typeof value !== 'object') {
|
|
16244
16526
|
return { owned: [], watched: [] };
|
|
@@ -16500,6 +16782,552 @@ const clientManagerMachine = xstate.setup({
|
|
|
16500
16782
|
},
|
|
16501
16783
|
});
|
|
16502
16784
|
|
|
16785
|
+
function msToUnixSeconds(ms) {
|
|
16786
|
+
if (ms == null || !Number.isFinite(ms))
|
|
16787
|
+
return 0;
|
|
16788
|
+
// Heuristic: values already in seconds are small; ms are large
|
|
16789
|
+
if (ms > 1e12)
|
|
16790
|
+
return Math.floor(ms / 1000);
|
|
16791
|
+
if (ms > 1e10)
|
|
16792
|
+
return Math.floor(ms / 1000);
|
|
16793
|
+
return Math.floor(ms);
|
|
16794
|
+
}
|
|
16795
|
+
function toSnakeCaseName(name) {
|
|
16796
|
+
return name
|
|
16797
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
16798
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
16799
|
+
.toLowerCase();
|
|
16800
|
+
}
|
|
16801
|
+
function parsePropertyValue(raw) {
|
|
16802
|
+
if (raw == null)
|
|
16803
|
+
return '';
|
|
16804
|
+
const t = raw.trim();
|
|
16805
|
+
if ((t.startsWith('[') && t.endsWith(']')) ||
|
|
16806
|
+
(t.startsWith('{') && t.endsWith('}'))) {
|
|
16807
|
+
try {
|
|
16808
|
+
return JSON.parse(t);
|
|
16809
|
+
}
|
|
16810
|
+
catch {
|
|
16811
|
+
return raw;
|
|
16812
|
+
}
|
|
16813
|
+
}
|
|
16814
|
+
return raw;
|
|
16815
|
+
}
|
|
16816
|
+
function attestationFromRaw(raw) {
|
|
16817
|
+
if (!raw || !raw.trim())
|
|
16818
|
+
return null;
|
|
16819
|
+
try {
|
|
16820
|
+
const parsed = JSON.parse(raw);
|
|
16821
|
+
if (parsed && typeof parsed.id === 'string')
|
|
16822
|
+
return parsed;
|
|
16823
|
+
}
|
|
16824
|
+
catch {
|
|
16825
|
+
// fall through
|
|
16826
|
+
}
|
|
16827
|
+
return null;
|
|
16828
|
+
}
|
|
16829
|
+
function seedRowToAttestation(row) {
|
|
16830
|
+
if (!row.uid || !eas.isValidEasAttestationUid(row.uid))
|
|
16831
|
+
return null;
|
|
16832
|
+
const fromRaw = attestationFromRaw(row.attestationRaw);
|
|
16833
|
+
if (fromRaw) {
|
|
16834
|
+
const schemaName = row.schemaName ??
|
|
16835
|
+
fromRaw.schema?.schemaNames?.[0]?.name ??
|
|
16836
|
+
row.type ??
|
|
16837
|
+
'unknown';
|
|
16838
|
+
return {
|
|
16839
|
+
...fromRaw,
|
|
16840
|
+
id: row.uid,
|
|
16841
|
+
schema: {
|
|
16842
|
+
schemaNames: [{ name: schemaName }],
|
|
16843
|
+
},
|
|
16844
|
+
timeCreated: fromRaw.timeCreated ||
|
|
16845
|
+
msToUnixSeconds(row.attestationCreatedAt),
|
|
16846
|
+
attester: fromRaw.attester ?? row.publisher ?? undefined,
|
|
16847
|
+
schemaId: fromRaw.schemaId || row.schemaUid || '',
|
|
16848
|
+
};
|
|
16849
|
+
}
|
|
16850
|
+
const schemaName = row.schemaName ?? row.type ?? 'unknown';
|
|
16851
|
+
return {
|
|
16852
|
+
id: row.uid,
|
|
16853
|
+
decodedDataJson: '',
|
|
16854
|
+
refUID: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
16855
|
+
schemaId: row.schemaUid || '',
|
|
16856
|
+
timeCreated: msToUnixSeconds(row.attestationCreatedAt),
|
|
16857
|
+
attester: row.publisher ?? undefined,
|
|
16858
|
+
schema: { schemaNames: [{ name: schemaName }] },
|
|
16859
|
+
};
|
|
16860
|
+
}
|
|
16861
|
+
function versionRowToAttestation(row) {
|
|
16862
|
+
if (!row.uid || !eas.isValidEasAttestationUid(row.uid))
|
|
16863
|
+
return null;
|
|
16864
|
+
if (!row.seedUid)
|
|
16865
|
+
return null;
|
|
16866
|
+
const fromRaw = attestationFromRaw(row.attestationRaw);
|
|
16867
|
+
if (fromRaw) {
|
|
16868
|
+
return {
|
|
16869
|
+
...fromRaw,
|
|
16870
|
+
id: row.uid,
|
|
16871
|
+
refUID: row.seedUid,
|
|
16872
|
+
timeCreated: fromRaw.timeCreated ||
|
|
16873
|
+
msToUnixSeconds(row.attestationCreatedAt),
|
|
16874
|
+
attester: fromRaw.attester ?? row.publisher ?? undefined,
|
|
16875
|
+
};
|
|
16876
|
+
}
|
|
16877
|
+
return {
|
|
16878
|
+
id: row.uid,
|
|
16879
|
+
decodedDataJson: '',
|
|
16880
|
+
refUID: row.seedUid,
|
|
16881
|
+
schemaId: '',
|
|
16882
|
+
timeCreated: msToUnixSeconds(row.attestationCreatedAt),
|
|
16883
|
+
attester: row.publisher ?? undefined,
|
|
16884
|
+
};
|
|
16885
|
+
}
|
|
16886
|
+
function metadataRowToAttestation(row) {
|
|
16887
|
+
if (!row.uid || !eas.isValidEasAttestationUid(row.uid))
|
|
16888
|
+
return null;
|
|
16889
|
+
if (!row.versionUid)
|
|
16890
|
+
return null;
|
|
16891
|
+
const fromRaw = attestationFromRaw(row.attestationRaw);
|
|
16892
|
+
if (fromRaw) {
|
|
16893
|
+
return {
|
|
16894
|
+
...fromRaw,
|
|
16895
|
+
id: row.uid,
|
|
16896
|
+
refUID: row.versionUid,
|
|
16897
|
+
schemaId: fromRaw.schemaId || row.schemaUid || '',
|
|
16898
|
+
timeCreated: fromRaw.timeCreated ||
|
|
16899
|
+
msToUnixSeconds(row.attestationCreatedAt),
|
|
16900
|
+
attester: fromRaw.attester ?? row.publisher ?? undefined,
|
|
16901
|
+
};
|
|
16902
|
+
}
|
|
16903
|
+
const name = row.propertyName
|
|
16904
|
+
? toSnakeCaseName(row.propertyName)
|
|
16905
|
+
: 'unknown';
|
|
16906
|
+
const value = parsePropertyValue(row.propertyValue);
|
|
16907
|
+
const type = row.easDataType || 'string';
|
|
16908
|
+
return {
|
|
16909
|
+
id: row.uid,
|
|
16910
|
+
decodedDataJson: JSON.stringify([{ value: { name, value, type } }]),
|
|
16911
|
+
refUID: row.versionUid,
|
|
16912
|
+
schemaId: row.schemaUid || '',
|
|
16913
|
+
timeCreated: msToUnixSeconds(row.attestationCreatedAt),
|
|
16914
|
+
attester: row.publisher ?? undefined,
|
|
16915
|
+
};
|
|
16916
|
+
}
|
|
16917
|
+
async function resolveSchemaNameForSeedType(appDb, seedType) {
|
|
16918
|
+
if (!seedType)
|
|
16919
|
+
return null;
|
|
16920
|
+
const normalized = lodashEs.startCase(seedType);
|
|
16921
|
+
try {
|
|
16922
|
+
const schemaRows = await appDb
|
|
16923
|
+
.select({ schemaName: schemas.name })
|
|
16924
|
+
.from(models$1)
|
|
16925
|
+
.innerJoin(modelSchemas, drizzleOrm.eq(models$1.id, modelSchemas.modelId))
|
|
16926
|
+
.innerJoin(schemas, drizzleOrm.eq(modelSchemas.schemaId, schemas.id))
|
|
16927
|
+
.where(drizzleOrm.eq(models$1.name, normalized))
|
|
16928
|
+
.limit(1);
|
|
16929
|
+
if (schemaRows[0]?.schemaName)
|
|
16930
|
+
return schemaRows[0].schemaName;
|
|
16931
|
+
}
|
|
16932
|
+
catch {
|
|
16933
|
+
// ignore
|
|
16934
|
+
}
|
|
16935
|
+
return seedType;
|
|
16936
|
+
}
|
|
16937
|
+
function monthBoundsUnix(year, month) {
|
|
16938
|
+
const startDate = new Date(year, month - 1, 1);
|
|
16939
|
+
const endDate = new Date(year, month, 0, 23, 59, 59);
|
|
16940
|
+
const startTs = Math.floor(startDate.getTime() / 1000);
|
|
16941
|
+
const endTs = Math.floor(endDate.getTime() / 1000) + 1;
|
|
16942
|
+
return { startTs, endTs };
|
|
16943
|
+
}
|
|
16944
|
+
async function listPublishedSeedRows(schemaName, opts) {
|
|
16945
|
+
const appDb = BaseDb.getAppDb();
|
|
16946
|
+
if (!appDb)
|
|
16947
|
+
return [];
|
|
16948
|
+
const snakeType = schemaName.includes('_')
|
|
16949
|
+
? schemaName
|
|
16950
|
+
: schemaName.replace(/([A-Z])/g, (m, i) => i === 0 ? m.toLowerCase() : `_${m.toLowerCase()}`);
|
|
16951
|
+
// Prefer exact type match (EAS schema names are usually lowercase singular)
|
|
16952
|
+
const typeCandidates = Array.from(new Set([schemaName, schemaName.toLowerCase(), snakeType.toLowerCase()]));
|
|
16953
|
+
const rows = await appDb
|
|
16954
|
+
.select({
|
|
16955
|
+
uid: seeds.uid,
|
|
16956
|
+
schemaUid: seeds.schemaUid,
|
|
16957
|
+
type: seeds.type,
|
|
16958
|
+
publisher: seeds.publisher,
|
|
16959
|
+
attestationRaw: seeds.attestationRaw,
|
|
16960
|
+
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
16961
|
+
revokedAt: seeds.revokedAt,
|
|
16962
|
+
markedForDeletion: seeds._markedForDeletion,
|
|
16963
|
+
})
|
|
16964
|
+
.from(seeds)
|
|
16965
|
+
.where(drizzleOrm.and(drizzleOrm.inArray(seeds.type, typeCandidates), drizzleOrm.isNotNull(seeds.uid), drizzleOrm.or(drizzleOrm.isNull(seeds.revokedAt), drizzleOrm.eq(seeds.revokedAt, 0)), drizzleOrm.or(drizzleOrm.isNull(seeds._markedForDeletion), drizzleOrm.eq(seeds._markedForDeletion, 0))))
|
|
16966
|
+
.orderBy(drizzleOrm.desc(seeds.attestationCreatedAt));
|
|
16967
|
+
const out = [];
|
|
16968
|
+
for (const row of rows) {
|
|
16969
|
+
if (!row.uid || !eas.isValidEasAttestationUid(row.uid))
|
|
16970
|
+
continue;
|
|
16971
|
+
// Must have at least one published version
|
|
16972
|
+
const versionRows = await appDb
|
|
16973
|
+
.select({
|
|
16974
|
+
uid: versions.uid,
|
|
16975
|
+
})
|
|
16976
|
+
.from(versions)
|
|
16977
|
+
.where(drizzleOrm.eq(versions.seedUid, row.uid))
|
|
16978
|
+
.orderBy(drizzleOrm.desc(versions.createdAt));
|
|
16979
|
+
const hasPublished = versionRows.some((v) => v.uid && eas.isValidEasAttestationUid(v.uid));
|
|
16980
|
+
if (!hasPublished)
|
|
16981
|
+
continue;
|
|
16982
|
+
const schemaResolved = await resolveSchemaNameForSeedType(appDb, row.type);
|
|
16983
|
+
const att = seedRowToAttestation({
|
|
16984
|
+
...row,
|
|
16985
|
+
schemaName: schemaResolved === schemaName ? schemaName : (schemaResolved ?? schemaName),
|
|
16986
|
+
});
|
|
16987
|
+
if (!att)
|
|
16988
|
+
continue;
|
|
16989
|
+
// Force requested schema name so assembleSeeds filters correctly
|
|
16990
|
+
att.schema = { schemaNames: [{ name: schemaName }] };
|
|
16991
|
+
if (opts?.startTs != null || opts?.endTs != null) {
|
|
16992
|
+
const t = att.timeCreated;
|
|
16993
|
+
if (opts.startTs != null && t < opts.startTs)
|
|
16994
|
+
continue;
|
|
16995
|
+
if (opts.endTs != null && t >= opts.endTs)
|
|
16996
|
+
continue;
|
|
16997
|
+
}
|
|
16998
|
+
out.push(att);
|
|
16999
|
+
}
|
|
17000
|
+
return out;
|
|
17001
|
+
}
|
|
17002
|
+
/**
|
|
17003
|
+
* SDK local QueryDataSource: published Seeds/Versions/metadata from SQLite.
|
|
17004
|
+
*/
|
|
17005
|
+
function createLocalQueryDataSource() {
|
|
17006
|
+
return {
|
|
17007
|
+
kind: 'local',
|
|
17008
|
+
async getSeedByUid(seedUid) {
|
|
17009
|
+
const appDb = BaseDb.getAppDb();
|
|
17010
|
+
if (!appDb || !seedUid)
|
|
17011
|
+
return null;
|
|
17012
|
+
const rows = await appDb
|
|
17013
|
+
.select({
|
|
17014
|
+
uid: seeds.uid,
|
|
17015
|
+
schemaUid: seeds.schemaUid,
|
|
17016
|
+
type: seeds.type,
|
|
17017
|
+
publisher: seeds.publisher,
|
|
17018
|
+
attestationRaw: seeds.attestationRaw,
|
|
17019
|
+
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
17020
|
+
revokedAt: seeds.revokedAt,
|
|
17021
|
+
})
|
|
17022
|
+
.from(seeds)
|
|
17023
|
+
.where(drizzleOrm.eq(seeds.uid, seedUid))
|
|
17024
|
+
.limit(1);
|
|
17025
|
+
const row = rows[0];
|
|
17026
|
+
if (!row?.uid || !eas.isValidEasAttestationUid(row.uid))
|
|
17027
|
+
return null;
|
|
17028
|
+
if (row.revokedAt != null && row.revokedAt !== 0)
|
|
17029
|
+
return null;
|
|
17030
|
+
const schemaName = await resolveSchemaNameForSeedType(appDb, row.type);
|
|
17031
|
+
return seedRowToAttestation({ ...row, schemaName });
|
|
17032
|
+
},
|
|
17033
|
+
async listSeedsBySchemaName(schemaName, opts) {
|
|
17034
|
+
const all = await listPublishedSeedRows(schemaName);
|
|
17035
|
+
return all.slice(opts.skip, opts.skip + opts.limit);
|
|
17036
|
+
},
|
|
17037
|
+
async listSeedsBySchemaNameForMonth(schemaName, year, month) {
|
|
17038
|
+
const { startTs, endTs } = monthBoundsUnix(year, month);
|
|
17039
|
+
return listPublishedSeedRows(schemaName, { startTs, endTs });
|
|
17040
|
+
},
|
|
17041
|
+
async getVersionsForSeed(seedUid) {
|
|
17042
|
+
return this.getVersionsForSeeds([seedUid]);
|
|
17043
|
+
},
|
|
17044
|
+
async getVersionsForSeeds(seedUids) {
|
|
17045
|
+
const appDb = BaseDb.getAppDb();
|
|
17046
|
+
if (!appDb || seedUids.length === 0)
|
|
17047
|
+
return [];
|
|
17048
|
+
const rows = await appDb
|
|
17049
|
+
.select({
|
|
17050
|
+
uid: versions.uid,
|
|
17051
|
+
seedUid: versions.seedUid,
|
|
17052
|
+
publisher: versions.publisher,
|
|
17053
|
+
attestationRaw: versions.attestationRaw,
|
|
17054
|
+
attestationCreatedAt: versions.attestationCreatedAt,
|
|
17055
|
+
})
|
|
17056
|
+
.from(versions)
|
|
17057
|
+
.where(drizzleOrm.inArray(versions.seedUid, seedUids));
|
|
17058
|
+
const out = [];
|
|
17059
|
+
for (const row of rows) {
|
|
17060
|
+
const att = versionRowToAttestation(row);
|
|
17061
|
+
if (att)
|
|
17062
|
+
out.push(att);
|
|
17063
|
+
}
|
|
17064
|
+
return out;
|
|
17065
|
+
},
|
|
17066
|
+
async getPropertiesForVersionUids(versionUids) {
|
|
17067
|
+
const appDb = BaseDb.getAppDb();
|
|
17068
|
+
if (!appDb || versionUids.length === 0)
|
|
17069
|
+
return [];
|
|
17070
|
+
const rows = await appDb
|
|
17071
|
+
.select({
|
|
17072
|
+
uid: metadata$1.uid,
|
|
17073
|
+
schemaUid: metadata$1.schemaUid,
|
|
17074
|
+
propertyName: metadata$1.propertyName,
|
|
17075
|
+
propertyValue: metadata$1.propertyValue,
|
|
17076
|
+
easDataType: metadata$1.easDataType,
|
|
17077
|
+
versionUid: metadata$1.versionUid,
|
|
17078
|
+
publisher: metadata$1.publisher,
|
|
17079
|
+
attestationRaw: metadata$1.attestationRaw,
|
|
17080
|
+
attestationCreatedAt: metadata$1.attestationCreatedAt,
|
|
17081
|
+
})
|
|
17082
|
+
.from(metadata$1)
|
|
17083
|
+
.where(drizzleOrm.inArray(metadata$1.versionUid, versionUids));
|
|
17084
|
+
const out = [];
|
|
17085
|
+
for (const row of rows) {
|
|
17086
|
+
const att = metadataRowToAttestation(row);
|
|
17087
|
+
if (att)
|
|
17088
|
+
out.push(att);
|
|
17089
|
+
}
|
|
17090
|
+
return out;
|
|
17091
|
+
},
|
|
17092
|
+
async getSeedsByUids(uids) {
|
|
17093
|
+
const appDb = BaseDb.getAppDb();
|
|
17094
|
+
if (!appDb || uids.length === 0)
|
|
17095
|
+
return [];
|
|
17096
|
+
const rows = await appDb
|
|
17097
|
+
.select({
|
|
17098
|
+
uid: seeds.uid,
|
|
17099
|
+
schemaUid: seeds.schemaUid,
|
|
17100
|
+
type: seeds.type,
|
|
17101
|
+
publisher: seeds.publisher,
|
|
17102
|
+
attestationRaw: seeds.attestationRaw,
|
|
17103
|
+
attestationCreatedAt: seeds.attestationCreatedAt,
|
|
17104
|
+
revokedAt: seeds.revokedAt,
|
|
17105
|
+
})
|
|
17106
|
+
.from(seeds)
|
|
17107
|
+
.where(drizzleOrm.inArray(seeds.uid, uids));
|
|
17108
|
+
const out = [];
|
|
17109
|
+
for (const row of rows) {
|
|
17110
|
+
if (row.revokedAt != null && row.revokedAt !== 0)
|
|
17111
|
+
continue;
|
|
17112
|
+
const schemaName = await resolveSchemaNameForSeedType(appDb, row.type);
|
|
17113
|
+
const att = seedRowToAttestation({ ...row, schemaName });
|
|
17114
|
+
if (att)
|
|
17115
|
+
out.push(att);
|
|
17116
|
+
}
|
|
17117
|
+
return out;
|
|
17118
|
+
},
|
|
17119
|
+
async readStorageBody(ref) {
|
|
17120
|
+
try {
|
|
17121
|
+
if (ref.localPathHint) {
|
|
17122
|
+
const text = await BaseFileManager.readFileAsString(ref.localPathHint);
|
|
17123
|
+
if (text)
|
|
17124
|
+
return text;
|
|
17125
|
+
}
|
|
17126
|
+
// Common layout: html/{name}.html under filesDir
|
|
17127
|
+
if (typeof ref.value === 'string') {
|
|
17128
|
+
const v = ref.value.trim();
|
|
17129
|
+
// Absolute or relative file path already on disk
|
|
17130
|
+
if (v.includes('/') && !v.startsWith('http')) {
|
|
17131
|
+
try {
|
|
17132
|
+
const text = await BaseFileManager.readFileAsString(v);
|
|
17133
|
+
if (text)
|
|
17134
|
+
return text;
|
|
17135
|
+
}
|
|
17136
|
+
catch {
|
|
17137
|
+
// try under html/
|
|
17138
|
+
}
|
|
17139
|
+
}
|
|
17140
|
+
const htmlPath = BaseFileManager.getFilesPath('html', v.endsWith('.html') ? v : `${v}.html`);
|
|
17141
|
+
try {
|
|
17142
|
+
const text = await BaseFileManager.readFileAsString(htmlPath);
|
|
17143
|
+
if (text)
|
|
17144
|
+
return text;
|
|
17145
|
+
}
|
|
17146
|
+
catch {
|
|
17147
|
+
// fall through
|
|
17148
|
+
}
|
|
17149
|
+
}
|
|
17150
|
+
}
|
|
17151
|
+
catch {
|
|
17152
|
+
return null;
|
|
17153
|
+
}
|
|
17154
|
+
return null;
|
|
17155
|
+
},
|
|
17156
|
+
};
|
|
17157
|
+
}
|
|
17158
|
+
|
|
17159
|
+
let registered = false;
|
|
17160
|
+
/**
|
|
17161
|
+
* Register the SDK SQLite/files adapter with `@seedprotocol/query`.
|
|
17162
|
+
* Safe to call multiple times; re-registers with a fresh adapter instance.
|
|
17163
|
+
* No-op when the app DB is not ready yet (unless `force`).
|
|
17164
|
+
*/
|
|
17165
|
+
function registerSeedQueryLocalSource(options) {
|
|
17166
|
+
try {
|
|
17167
|
+
query.registerLocalQuerySource(createLocalQueryDataSource());
|
|
17168
|
+
registered = true;
|
|
17169
|
+
return true;
|
|
17170
|
+
}
|
|
17171
|
+
catch (err) {
|
|
17172
|
+
console.warn('[sdk/query] registerSeedQueryLocalSource failed:', err);
|
|
17173
|
+
return false;
|
|
17174
|
+
}
|
|
17175
|
+
}
|
|
17176
|
+
/** Unregister local query source (tests / client unload). */
|
|
17177
|
+
function unregisterSeedQueryLocalSource() {
|
|
17178
|
+
query.clearLocalQuerySource();
|
|
17179
|
+
registered = false;
|
|
17180
|
+
}
|
|
17181
|
+
|
|
17182
|
+
const READ_ONLY_ERROR = 'Item is read-only: you do not own this item';
|
|
17183
|
+
async function getSeedRowForItem(item) {
|
|
17184
|
+
const appDb = BaseDb.getAppDb();
|
|
17185
|
+
if (!appDb)
|
|
17186
|
+
return null;
|
|
17187
|
+
const conditions = [];
|
|
17188
|
+
if (item.seedLocalId)
|
|
17189
|
+
conditions.push(drizzleOrm.eq(seeds.localId, item.seedLocalId));
|
|
17190
|
+
if (item.seedUid)
|
|
17191
|
+
conditions.push(drizzleOrm.eq(seeds.uid, item.seedUid));
|
|
17192
|
+
if (conditions.length === 0)
|
|
17193
|
+
return null;
|
|
17194
|
+
const seedRows = await appDb
|
|
17195
|
+
.select({
|
|
17196
|
+
publisher: seeds.publisher,
|
|
17197
|
+
attestationRaw: seeds.attestationRaw,
|
|
17198
|
+
uid: seeds.uid,
|
|
17199
|
+
})
|
|
17200
|
+
.from(seeds)
|
|
17201
|
+
.where(conditions.length === 1 ? conditions[0] : drizzleOrm.or(...conditions))
|
|
17202
|
+
.limit(1);
|
|
17203
|
+
if (!seedRows || seedRows.length === 0)
|
|
17204
|
+
return null;
|
|
17205
|
+
return seedRows[0];
|
|
17206
|
+
}
|
|
17207
|
+
/** Resolve publisher from seed row: `publisher` column, else `attestationRaw.attester`. */
|
|
17208
|
+
function resolvePublisherFromSeedRow(row) {
|
|
17209
|
+
if (row.publisher)
|
|
17210
|
+
return row.publisher;
|
|
17211
|
+
if (row.attestationRaw) {
|
|
17212
|
+
try {
|
|
17213
|
+
const parsed = JSON.parse(row.attestationRaw);
|
|
17214
|
+
return parsed.attester ?? null;
|
|
17215
|
+
}
|
|
17216
|
+
catch {
|
|
17217
|
+
return null;
|
|
17218
|
+
}
|
|
17219
|
+
}
|
|
17220
|
+
return null;
|
|
17221
|
+
}
|
|
17222
|
+
/**
|
|
17223
|
+
* Checks if the current user owns the item (publisher is in owned addresses).
|
|
17224
|
+
* Locally created items (no publisher, no attestationRaw) are considered owned.
|
|
17225
|
+
* Includes getAdditionalSyncAddresses (e.g. `modularAccountModuleContract` when configured)
|
|
17226
|
+
* so ownership aligns with EAS sync when the publisher/attester matches those addresses.
|
|
17227
|
+
*/
|
|
17228
|
+
async function isItemOwned(item) {
|
|
17229
|
+
const row = await getSeedRowForItem(item);
|
|
17230
|
+
if (!row)
|
|
17231
|
+
return false;
|
|
17232
|
+
const publisher = resolvePublisherFromSeedRow(row);
|
|
17233
|
+
if (!publisher) {
|
|
17234
|
+
if (!row.uid && !row.attestationRaw) {
|
|
17235
|
+
return true;
|
|
17236
|
+
}
|
|
17237
|
+
return false;
|
|
17238
|
+
}
|
|
17239
|
+
let addressesToCheck = await getOwnedAddressesFromDb();
|
|
17240
|
+
const ownedSet = new Set(addressesToCheck.map((a) => a.toLowerCase()));
|
|
17241
|
+
return ownedSet.has(publisher.toLowerCase());
|
|
17242
|
+
}
|
|
17243
|
+
/**
|
|
17244
|
+
* Throws if the item is not owned. Use before write operations (publish, save, destroy).
|
|
17245
|
+
*/
|
|
17246
|
+
async function assertItemOwned(item) {
|
|
17247
|
+
const owned = await isItemOwned(item);
|
|
17248
|
+
if (!owned) {
|
|
17249
|
+
throw new Error(READ_ONLY_ERROR);
|
|
17250
|
+
}
|
|
17251
|
+
}
|
|
17252
|
+
|
|
17253
|
+
var ownership = /*#__PURE__*/Object.freeze({
|
|
17254
|
+
__proto__: null,
|
|
17255
|
+
assertItemOwned: assertItemOwned,
|
|
17256
|
+
isItemOwned: isItemOwned,
|
|
17257
|
+
resolvePublisherFromSeedRow: resolvePublisherFromSeedRow
|
|
17258
|
+
});
|
|
17259
|
+
|
|
17260
|
+
const emptyResult = () => ({
|
|
17261
|
+
removedSeedLocalIds: [],
|
|
17262
|
+
removedSeedUids: [],
|
|
17263
|
+
});
|
|
17264
|
+
function normalizeAddresses(addresses) {
|
|
17265
|
+
return [
|
|
17266
|
+
...new Set(addresses
|
|
17267
|
+
.filter((a) => typeof a === 'string' && a.length > 0)
|
|
17268
|
+
.map((a) => a.toLowerCase())),
|
|
17269
|
+
];
|
|
17270
|
+
}
|
|
17271
|
+
/**
|
|
17272
|
+
* Find local on-chain seed copies for the given publisher addresses (no delete).
|
|
17273
|
+
* Drafts (no uid and no attestationRaw) are excluded.
|
|
17274
|
+
*/
|
|
17275
|
+
async function findLocalOnchainCopiesForAddresses(addresses) {
|
|
17276
|
+
const normalized = normalizeAddresses(addresses);
|
|
17277
|
+
if (normalized.length === 0) {
|
|
17278
|
+
return emptyResult();
|
|
17279
|
+
}
|
|
17280
|
+
const appDb = BaseDb.getAppDb();
|
|
17281
|
+
if (!appDb) {
|
|
17282
|
+
return emptyResult();
|
|
17283
|
+
}
|
|
17284
|
+
const addressSet = new Set(normalized);
|
|
17285
|
+
const candidateRows = (await appDb
|
|
17286
|
+
.select({
|
|
17287
|
+
localId: seeds.localId,
|
|
17288
|
+
uid: seeds.uid,
|
|
17289
|
+
publisher: seeds.publisher,
|
|
17290
|
+
attestationRaw: seeds.attestationRaw,
|
|
17291
|
+
})
|
|
17292
|
+
.from(seeds)
|
|
17293
|
+
.where(drizzleOrm.or(drizzleOrm.isNotNull(seeds.uid), drizzleOrm.isNotNull(seeds.attestationRaw))));
|
|
17294
|
+
const matched = candidateRows.filter((row) => {
|
|
17295
|
+
if (!row.localId)
|
|
17296
|
+
return false;
|
|
17297
|
+
const publisher = resolvePublisherFromSeedRow(row);
|
|
17298
|
+
return publisher != null && addressSet.has(publisher.toLowerCase());
|
|
17299
|
+
});
|
|
17300
|
+
return {
|
|
17301
|
+
removedSeedLocalIds: matched.map((r) => r.localId).filter(Boolean),
|
|
17302
|
+
removedSeedUids: matched
|
|
17303
|
+
.map((r) => r.uid)
|
|
17304
|
+
.filter((u) => typeof u === 'string' && u.length > 0),
|
|
17305
|
+
};
|
|
17306
|
+
}
|
|
17307
|
+
/**
|
|
17308
|
+
* Hard-delete the given seed local ids and related local rows (cascade).
|
|
17309
|
+
* Does not touch schemas, app_state, or chain.
|
|
17310
|
+
*/
|
|
17311
|
+
async function hardDeleteLocalSeedsByLocalIds(seedLocalIds) {
|
|
17312
|
+
if (seedLocalIds.length === 0)
|
|
17313
|
+
return;
|
|
17314
|
+
const appDb = BaseDb.getAppDb();
|
|
17315
|
+
if (!appDb)
|
|
17316
|
+
return;
|
|
17317
|
+
await appDb
|
|
17318
|
+
.delete(htmlEmbeddedImageCoPublish)
|
|
17319
|
+
.where(drizzleOrm.or(drizzleOrm.inArray(htmlEmbeddedImageCoPublish.parentSeedLocalId, seedLocalIds), drizzleOrm.inArray(htmlEmbeddedImageCoPublish.htmlSeedLocalId, seedLocalIds), drizzleOrm.inArray(htmlEmbeddedImageCoPublish.imageSeedLocalId, seedLocalIds)));
|
|
17320
|
+
await appDb
|
|
17321
|
+
.delete(arweaveL1FinalizeJobs)
|
|
17322
|
+
.where(drizzleOrm.inArray(arweaveL1FinalizeJobs.seedLocalId, seedLocalIds));
|
|
17323
|
+
await appDb
|
|
17324
|
+
.delete(publishProcesses)
|
|
17325
|
+
.where(drizzleOrm.inArray(publishProcesses.seedLocalId, seedLocalIds));
|
|
17326
|
+
await appDb.delete(metadata$1).where(drizzleOrm.inArray(metadata$1.seedLocalId, seedLocalIds));
|
|
17327
|
+
await appDb.delete(versions).where(drizzleOrm.inArray(versions.seedLocalId, seedLocalIds));
|
|
17328
|
+
await appDb.delete(seeds).where(drizzleOrm.inArray(seeds.localId, seedLocalIds));
|
|
17329
|
+
}
|
|
17330
|
+
|
|
16503
17331
|
const logger$3 = debug('seedSdk:client');
|
|
16504
17332
|
const clientManager = xstate.createActor(clientManagerMachine, {
|
|
16505
17333
|
input: {
|
|
@@ -16604,6 +17432,8 @@ const clientInstance = {
|
|
|
16604
17432
|
}
|
|
16605
17433
|
throw error;
|
|
16606
17434
|
}
|
|
17435
|
+
// Wire `@seedprotocol/query` local source once DB is ready
|
|
17436
|
+
registerSeedQueryLocalSource();
|
|
16607
17437
|
},
|
|
16608
17438
|
setAddresses: async (addresses) => {
|
|
16609
17439
|
ensureInitialized();
|
|
@@ -16626,6 +17456,29 @@ const clientInstance = {
|
|
|
16626
17456
|
ensureInitialized();
|
|
16627
17457
|
return getWatchedAddressesFromDb();
|
|
16628
17458
|
},
|
|
17459
|
+
/**
|
|
17460
|
+
* Hard-delete local on-chain seed copies for the given publisher addresses.
|
|
17461
|
+
* Drafts (no uid / attestationRaw) are kept. Chain is untouched; reconnect can rehydrate via syncFromEas.
|
|
17462
|
+
*/
|
|
17463
|
+
removeLocalCopiesForAddresses: async (addresses) => {
|
|
17464
|
+
ensureInitialized();
|
|
17465
|
+
const list = Array.isArray(addresses) ? addresses : [];
|
|
17466
|
+
const matched = await findLocalOnchainCopiesForAddresses(list);
|
|
17467
|
+
const cacheIds = [
|
|
17468
|
+
...matched.removedSeedLocalIds,
|
|
17469
|
+
...matched.removedSeedUids,
|
|
17470
|
+
];
|
|
17471
|
+
if (cacheIds.length > 0) {
|
|
17472
|
+
Item.dropCachedInstancesForSeedIds(cacheIds);
|
|
17473
|
+
}
|
|
17474
|
+
await hardDeleteLocalSeedsByLocalIds(matched.removedSeedLocalIds);
|
|
17475
|
+
eventEmitter.emit(LOCAL_COPIES_REMOVED_EVENT, {
|
|
17476
|
+
addresses: list,
|
|
17477
|
+
removedSeedLocalIds: matched.removedSeedLocalIds,
|
|
17478
|
+
removedSeedUids: matched.removedSeedUids,
|
|
17479
|
+
});
|
|
17480
|
+
return matched;
|
|
17481
|
+
},
|
|
16629
17482
|
/**
|
|
16630
17483
|
* Syncs item attestations from EAS for the configured models and given addresses.
|
|
16631
17484
|
* Uses owned + watched addresses from DB when addresses are not provided.
|
|
@@ -16665,10 +17518,12 @@ const clientInstance = {
|
|
|
16665
17518
|
},
|
|
16666
17519
|
stop: () => {
|
|
16667
17520
|
ensureInitialized();
|
|
17521
|
+
unregisterSeedQueryLocalSource();
|
|
16668
17522
|
clientManager.stop();
|
|
16669
17523
|
},
|
|
16670
17524
|
unload: () => {
|
|
16671
17525
|
ensureInitialized();
|
|
17526
|
+
unregisterSeedQueryLocalSource();
|
|
16672
17527
|
clientManager.stop();
|
|
16673
17528
|
subscription.unsubscribe();
|
|
16674
17529
|
},
|
|
@@ -16851,7 +17706,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
|
|
|
16851
17706
|
// Lazy import cache for ModelProperty to avoid circular dependency
|
|
16852
17707
|
// Eagerly start loading to minimize delay on first access
|
|
16853
17708
|
let ModelPropertyClass = null;
|
|
16854
|
-
const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-
|
|
17709
|
+
const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-BA26rMV8.js'); })
|
|
16855
17710
|
.then(module => {
|
|
16856
17711
|
ModelPropertyClass = module.ModelProperty;
|
|
16857
17712
|
return ModelPropertyClass;
|
|
@@ -16868,7 +17723,7 @@ function getModelProperty() {
|
|
|
16868
17723
|
}
|
|
16869
17724
|
// Lazy import cache for Schema to avoid circular dependency
|
|
16870
17725
|
let SchemaClass = null;
|
|
16871
|
-
const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-
|
|
17726
|
+
const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); })
|
|
16872
17727
|
.then(module => {
|
|
16873
17728
|
SchemaClass = module.Schema;
|
|
16874
17729
|
return SchemaClass;
|
|
@@ -18773,7 +19628,7 @@ function resolveSdkDrizzleMigrationsDir(sdkRootDir) {
|
|
|
18773
19628
|
})();
|
|
18774
19629
|
// Also resolve relative to this module so temp-cwd tests / odd roots still find
|
|
18775
19630
|
// packages/sdk/src/db/drizzle (or dist/db/drizzle after publish).
|
|
18776
|
-
const moduleDir = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-
|
|
19631
|
+
const moduleDir = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-BD1b6zAi.js', document.baseURI).href))));
|
|
18777
19632
|
const candidates = [
|
|
18778
19633
|
path.join(root, 'db', 'drizzle'), // production: sdkRoot is dist/
|
|
18779
19634
|
path.join(root, 'dist', 'db', 'drizzle'), // sdk package root with built dist
|
|
@@ -18843,7 +19698,7 @@ class NodeDb {
|
|
|
18843
19698
|
logger$1('[Db.prepareDb] running migrations from %s', outDir);
|
|
18844
19699
|
await migrator.migrate(db, { migrationsFolder: outDir });
|
|
18845
19700
|
this.db = db;
|
|
18846
|
-
const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-
|
|
19701
|
+
const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-BWJI4eCj.js'); });
|
|
18847
19702
|
await backfillMetadataPropertyIds();
|
|
18848
19703
|
return this.db;
|
|
18849
19704
|
}
|
|
@@ -19045,6 +19900,27 @@ const saveModelsFromMarkdown = async (filePath, db) => {
|
|
|
19045
19900
|
return modelDefinitions;
|
|
19046
19901
|
};
|
|
19047
19902
|
|
|
19903
|
+
/**
|
|
19904
|
+
* Webpack / Next.js config helper for Seed Protocol apps.
|
|
19905
|
+
*/
|
|
19906
|
+
const withSeed = (config, webpack, isServer) => {
|
|
19907
|
+
config.plugins.push(new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
|
|
19908
|
+
resource.request = resource.request.replace(/^node:/, '');
|
|
19909
|
+
}));
|
|
19910
|
+
if (!isServer) {
|
|
19911
|
+
config.resolve.alias['fs'] = '@zenfs/core';
|
|
19912
|
+
config.resolve.alias['node:fs'] = '@zenfs/core';
|
|
19913
|
+
config.resolve.alias['node:path'] = 'path-browserify';
|
|
19914
|
+
config.resolve.alias['path'] = 'path-browserify';
|
|
19915
|
+
}
|
|
19916
|
+
if (isServer) {
|
|
19917
|
+
config.externals.push('@sqlite.org/sqlite-wasm');
|
|
19918
|
+
config.externals.push('chokidar');
|
|
19919
|
+
config.externals.push('arweave');
|
|
19920
|
+
}
|
|
19921
|
+
return config;
|
|
19922
|
+
};
|
|
19923
|
+
|
|
19048
19924
|
const logger = debug('seedSdk:node:helpers:PathResolver');
|
|
19049
19925
|
class NodePathResolver {
|
|
19050
19926
|
/** @deprecated Prefer BasePathResolver static methods or configure(). */
|
|
@@ -19371,7 +20247,6 @@ exports.getLatestPublishedVersionRow = getLatestPublishedVersionRow;
|
|
|
19371
20247
|
exports.getLatestSchemaVersion = getLatestSchemaVersion;
|
|
19372
20248
|
exports.getModelId = getModelId;
|
|
19373
20249
|
exports.getModelIdByFileId = getModelIdByFileId;
|
|
19374
|
-
exports.getOwnedAddressesFromDb = getOwnedAddressesFromDb;
|
|
19375
20250
|
exports.getPropertyData = getPropertyData$1;
|
|
19376
20251
|
exports.getPropertyIdForModelAndName = getPropertyIdForModelAndName;
|
|
19377
20252
|
exports.getRefValueType = getRefValueType;
|
|
@@ -19388,7 +20263,6 @@ exports.modelSchemas = modelSchemas;
|
|
|
19388
20263
|
exports.modelUids = modelUids;
|
|
19389
20264
|
exports.models = models$1;
|
|
19390
20265
|
exports.normalizeDataType = normalizeDataType;
|
|
19391
|
-
exports.parseEasRelationPropertyName = parseEasRelationPropertyName;
|
|
19392
20266
|
exports.parseListPropertyValueFromStorage = parseListPropertyValueFromStorage;
|
|
19393
20267
|
exports.parseMarkdownFrontmatter = parseMarkdownFrontmatter;
|
|
19394
20268
|
exports.processSeedConfig = processSeedConfig;
|
|
@@ -19411,5 +20285,6 @@ exports.transformImportToSchemaFile = transformImportToSchemaFile;
|
|
|
19411
20285
|
exports.unloadEntity = unloadEntity;
|
|
19412
20286
|
exports.versions = versions;
|
|
19413
20287
|
exports.waitForEntityIdle = waitForEntityIdle;
|
|
20288
|
+
exports.withSeed = withSeed;
|
|
19414
20289
|
exports.writeProcessMachine = writeProcessMachine;
|
|
19415
|
-
//# sourceMappingURL=index-
|
|
20290
|
+
//# sourceMappingURL=index-BD1b6zAi.js.map
|