@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,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('reflect-metadata');
|
|
4
|
-
var main_cjs = require('./index-
|
|
5
|
-
var property = require('./property-
|
|
4
|
+
var main_cjs = require('./index-BD1b6zAi.js');
|
|
5
|
+
var property = require('./property-D4IB0zBz.js');
|
|
6
6
|
require('immer');
|
|
7
7
|
require('xstate');
|
|
8
8
|
require('drizzle-orm/sqlite-core');
|
|
@@ -14,6 +14,7 @@ require('pluralize');
|
|
|
14
14
|
require('@sinclair/typebox');
|
|
15
15
|
require('nanoid');
|
|
16
16
|
require('nanoid-dictionary');
|
|
17
|
+
require('@seedprotocol/query');
|
|
17
18
|
require('drizzle-orm/casing');
|
|
18
19
|
require('lodash-es');
|
|
19
20
|
require('rxjs');
|
|
@@ -26,7 +27,6 @@ require('@libsql/client');
|
|
|
26
27
|
require('drizzle-orm/libsql');
|
|
27
28
|
require('drizzle-orm/libsql/migrator');
|
|
28
29
|
require('js-yaml');
|
|
29
|
-
require('@seedprotocol/webpack');
|
|
30
30
|
require('child_process');
|
|
31
31
|
require('@seedprotocol/arweave/node');
|
|
32
32
|
require('@seedprotocol/eas/node');
|
|
@@ -63,4 +63,4 @@ exports.TValidationRules = main_cjs.TValidationRules;
|
|
|
63
63
|
exports.Text = main_cjs.Text;
|
|
64
64
|
exports.normalizeDataType = main_cjs.normalizeDataType;
|
|
65
65
|
exports.getPropertySchema = property.getPropertySchema;
|
|
66
|
-
//# sourceMappingURL=index-
|
|
66
|
+
//# sourceMappingURL=index-DQggpLqI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-DQggpLqI.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser-BSf8HpnU.js","sources":["../../../src/platform/index.browser.ts"],"sourcesContent":["import { BrowserPathResolver } from '@/browser/helpers/PathResolver'\nimport { BrowserFileManager } from '@/browser/helpers/FileManager'\nimport { BrowserDb } from '@/browser/db/Db'\nimport { BrowserArweaveClient } from '@/browser/helpers/ArweaveClient'\nimport { BrowserEasClient } from '@/browser/helpers/EasClient'\nimport { BrowserQueryClient } from '@/browser/helpers/QueryClient'\nimport type { PlatformServices } from './types'\n\nexport function createPlatformServices(): PlatformServices {\n return {\n pathResolver: new BrowserPathResolver(),\n fileManager: new BrowserFileManager(),\n db: new BrowserDb(),\n arweaveClient: new BrowserArweaveClient(),\n easClient: new BrowserEasClient(),\n queryClient: new BrowserQueryClient(),\n }\n}\n"],"names":["BrowserPathResolver","BrowserFileManager","BrowserDb","BrowserArweaveClient","BrowserEasClient","BrowserQueryClient"],"mappings":";;;;;;;;;SAQgB,sBAAsB,GAAA;IACpC,OAAO;QACL,YAAY,EAAE,IAAIA,gCAAmB,EAAE;QACvC,WAAW,EAAE,IAAIC,8BAAkB,EAAE;QACrC,EAAE,EAAE,IAAIC,YAAS,EAAE;QACnB,aAAa,EAAE,IAAIC,kCAAoB,EAAE;QACzC,SAAS,EAAE,IAAIC,0BAAgB,EAAE;QACjC,WAAW,EAAE,IAAIC,8BAAkB,EAAE;KACtC;AACH
|
|
1
|
+
{"version":3,"file":"index.browser-BSf8HpnU.js","sources":["../../../src/platform/index.browser.ts"],"sourcesContent":["import { BrowserPathResolver } from '@/browser/helpers/PathResolver'\nimport { BrowserFileManager } from '@/browser/helpers/FileManager'\nimport { BrowserDb } from '@/browser/db/Db'\nimport { BrowserArweaveClient } from '@/browser/helpers/ArweaveClient'\nimport { BrowserEasClient } from '@/browser/helpers/EasClient'\nimport { BrowserQueryClient } from '@/browser/helpers/QueryClient'\nimport type { PlatformServices } from './types'\n\nexport function createPlatformServices(): PlatformServices {\n return {\n pathResolver: new BrowserPathResolver(),\n fileManager: new BrowserFileManager(),\n db: new BrowserDb(),\n arweaveClient: new BrowserArweaveClient(),\n easClient: new BrowserEasClient(),\n queryClient: new BrowserQueryClient(),\n }\n}\n"],"names":["BrowserPathResolver","BrowserFileManager","BrowserDb","BrowserArweaveClient","BrowserEasClient","BrowserQueryClient"],"mappings":";;;;;;;;;SAQgB,sBAAsB,GAAA;IACpC,OAAO;QACL,YAAY,EAAE,IAAIA,gCAAmB,EAAE;QACvC,WAAW,EAAE,IAAIC,8BAAkB,EAAE;QACrC,EAAE,EAAE,IAAIC,YAAS,EAAE;QACnB,aAAa,EAAE,IAAIC,kCAAoB,EAAE;QACzC,SAAS,EAAE,IAAIC,0BAAgB,EAAE;QACjC,WAAW,EAAE,IAAIC,8BAAkB,EAAE;KACtC;AACH;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pluralize = require('pluralize');
|
|
4
|
-
var main_cjs = require('./index-
|
|
4
|
+
var main_cjs = require('./index-BD1b6zAi.js');
|
|
5
5
|
var drizzleOrm = require('drizzle-orm');
|
|
6
6
|
require('immer');
|
|
7
7
|
require('reflect-metadata');
|
|
@@ -13,6 +13,7 @@ require('@seedprotocol/eas');
|
|
|
13
13
|
require('@sinclair/typebox');
|
|
14
14
|
require('nanoid');
|
|
15
15
|
require('nanoid-dictionary');
|
|
16
|
+
require('@seedprotocol/query');
|
|
16
17
|
require('drizzle-orm/casing');
|
|
17
18
|
require('lodash-es');
|
|
18
19
|
require('rxjs');
|
|
@@ -25,7 +26,6 @@ require('@libsql/client');
|
|
|
25
26
|
require('drizzle-orm/libsql');
|
|
26
27
|
require('drizzle-orm/libsql/migrator');
|
|
27
28
|
require('js-yaml');
|
|
28
|
-
require('@seedprotocol/webpack');
|
|
29
29
|
require('child_process');
|
|
30
30
|
require('@seedprotocol/arweave/node');
|
|
31
31
|
require('@seedprotocol/eas/node');
|
|
@@ -66,9 +66,9 @@ require('@seedprotocol/eas/node');
|
|
|
66
66
|
*/
|
|
67
67
|
const getPropertySchema = async (modelName, propertyName) => {
|
|
68
68
|
// Dynamic import to break circular dependency
|
|
69
|
-
const modelMod = await Promise.resolve().then(function () { return require('./index-
|
|
69
|
+
const modelMod = await Promise.resolve().then(function () { return require('./index-BD1b6zAi.js'); }).then(function (n) { return n.Model$1; });
|
|
70
70
|
const { Model } = modelMod;
|
|
71
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
71
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-Hgwq3L34.js'); });
|
|
72
72
|
const { Schema } = schemaMod;
|
|
73
73
|
const model = await Model.getByNameAsync(modelName);
|
|
74
74
|
if (!model) {
|
|
@@ -315,4 +315,4 @@ exports.TStorageType = main_cjs.TStorageType;
|
|
|
315
315
|
exports.Text = main_cjs.Text;
|
|
316
316
|
exports.normalizeDataType = main_cjs.normalizeDataType;
|
|
317
317
|
exports.getPropertySchema = getPropertySchema;
|
|
318
|
-
//# sourceMappingURL=property-
|
|
318
|
+
//# sourceMappingURL=property-D4IB0zBz.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property-D3Ww2_Qh.js","sources":["../../../src/helpers/property.ts"],"sourcesContent":["import { Static } from '@sinclair/typebox'\nimport { TProperty } from '@/Schema'\n// Dynamic import to break circular dependency: Model -> ... -> helpers/property -> Model\n// import { Model } from '@/Model/Model'\nimport pluralize from 'pluralize'\nimport { resolveStorageNameToSchemaName } from '@/helpers/metadataPropertyNames'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, properties, PropertyType } from '@/seedSchema'\nimport { eq, and } from 'drizzle-orm'\nimport { modelPropertiesToObject } from '@/helpers/model'\n\n// Re-export everything from property/index.ts to make it available when importing from helpers/property\nexport * from './property/index'\n\n/**\n * Gets the propertyRecordSchema object for a given model and property name.\n * \n * The propertyRecordSchema is the property definition object that contains\n * information about the property's data type, storage configuration, and\n * relationship details (for Relation and List types).\n * \n * This function first checks the database for property definitions (which may\n * have been edited), then falls back to schema files. This ensures that\n * edited properties persist across page reloads.\n * \n * This function handles property names that end with 'Id' or 'Ids' by automatically\n * looking up the base property name in the schema (e.g., 'authorId' -> 'author',\n * 'tagIds' -> 'tags').\n * \n * @param modelName - The name of the model (e.g., 'Article', 'Author')\n * @param propertyName - The name of the property (e.g., 'title', 'author', 'authorId', 'tags', 'tagIds')\n * @returns The propertyRecordSchema object (TProperty with optional _propertyFileId) or undefined if not found\n * \n * @example\n * ```typescript\n * const schema = await getPropertySchema('Article', 'title')\n * // Returns: { dataType: 'Text', ... }\n * \n * const relationSchema = await getPropertySchema('Article', 'author')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * \n * // Also works with Id/Ids suffixes\n * const relationSchemaById = await getPropertySchema('Article', 'authorId')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * ```\n */\nexport const getPropertySchema = async (\n modelName: string,\n propertyName: string,\n): Promise<(Static<typeof TProperty> & { _propertyFileId?: string }) | undefined> => {\n // Dynamic import to break circular dependency\n const modelMod = await import('../Model/Model')\n const { Model } = modelMod\n const schemaMod = await import('../Schema/Schema')\n const { Schema } = schemaMod\n const model = await Model.getByNameAsync(modelName)\n\n if (!model) {\n return undefined\n }\n \n // Get the original schema from Schema instance context (has ref fields from schema file)\n // This is more reliable than modelPropertiesToObject which depends on ModelProperty instances\n let schema: { [propertyName: string]: any } = {}\n try {\n const schemaName = model.schemaName\n if (schemaName) {\n const schemaInstance = Schema.create(schemaName, {\n waitForReady: false,\n }) as import('@/Schema/Schema').Schema\n const schemaContext = schemaInstance.getService().getSnapshot().context\n if (schemaContext.models && schemaContext.models[modelName]) {\n // Get properties from Schema context (original schema file data)\n const modelDef = schemaContext.models[modelName]\n schema = modelDef.properties || {}\n }\n }\n } catch (error) {\n // Fall through to modelPropertiesToObject\n }\n \n // Fallback to modelPropertiesToObject if Schema context doesn't have the data\n if (Object.keys(schema).length === 0) {\n const properties = model.properties || []\n if (properties.length === 0) {\n return undefined\n }\n schema = modelPropertiesToObject(properties)\n }\n \n // Helper to resolve property name (handles Id/Ids suffixes)\n const resolvePropertyName = (propName: string): string | undefined => {\n // First, try direct lookup\n if (schema[propName]) {\n return propName\n }\n\n // List-of-relation storage name (e.g. authorIdentityIds) -> schema key (authors)\n const listSchemaKey = resolveStorageNameToSchemaName(schema, propName)\n if (listSchemaKey && schema[listSchemaKey]) {\n return listSchemaKey\n }\n\n // Handle properties ending with 'Id' or 'Ids'\n let propertyNameWithoutId: string | undefined\n \n if (propName.endsWith('Id')) {\n propertyNameWithoutId = propName.slice(0, -2)\n } else if (propName.endsWith('Ids')) {\n propertyNameWithoutId = propName.slice(0, -3)\n propertyNameWithoutId = pluralize(propertyNameWithoutId)\n }\n \n if (propertyNameWithoutId && schema[propertyNameWithoutId]) {\n return propertyNameWithoutId\n }\n \n return undefined\n }\n \n const resolvedPropertyName = resolvePropertyName(propertyName)\n if (!resolvedPropertyName) {\n return undefined\n }\n \n // Try to get property from database first (may have edited values)\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n // Find the model in the database\n const modelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, modelName))\n .limit(1)\n \n if (modelRecords.length > 0) {\n const modelRecord = modelRecords[0]\n \n // Find the property in the database by name\n let propertyRecords = await db\n .select()\n .from(properties)\n .where(\n and(\n eq(properties.name, resolvedPropertyName),\n eq(properties.modelId, modelRecord.id!),\n ),\n )\n .limit(1)\n \n // If not found by name, check for renamed properties (orphaned DB properties)\n if (propertyRecords.length === 0) {\n // Get all properties for this model\n const allDbProperties = await db\n .select()\n .from(properties)\n .where(eq(properties.modelId, modelRecord.id!))\n \n // Get all schema property names to identify orphaned properties\n const schemaPropertyNames = new Set(Object.keys(schema))\n \n // Get the schema property definition to match characteristics\n const schemaPropertyDef = schema[resolvedPropertyName]\n \n if (schemaPropertyDef) {\n // Find orphaned properties (don't match any schema property name) that match characteristics\n const orphanedProperties = allDbProperties.filter((p: PropertyType) => \n !schemaPropertyNames.has(p.name) && // Doesn't match any schema property name\n p.dataType === schemaPropertyDef.dataType // Same dataType\n )\n \n // If there's exactly one orphaned property with matching characteristics, it's likely the renamed property\n // We can also match by refModelId if it's a relation\n if (orphanedProperties.length > 0) {\n let matchedProperty = orphanedProperties[0]\n \n // If it's a relation, try to match by refModelId\n if (schemaPropertyDef.ref) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaPropertyDef.ref))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n const expectedRefModelId = refModelRecords[0].id\n const matchingByRef = orphanedProperties.find((p: PropertyType) => p.refModelId === expectedRefModelId)\n if (matchingByRef) {\n matchedProperty = matchingByRef\n }\n }\n } else {\n // For non-relation properties, prefer ones without refModelId\n const withoutRef = orphanedProperties.find((p: PropertyType) => p.refModelId === null)\n if (withoutRef) {\n matchedProperty = withoutRef\n }\n }\n \n propertyRecords = [matchedProperty]\n }\n }\n }\n \n if (propertyRecords.length > 0) {\n const propertyRecord = propertyRecords[0]\n \n // Get the base schema from file to merge with database values\n // Use the schema object created earlier, not model.schema (which doesn't exist)\n const schemaFromFile = schema[resolvedPropertyName]\n \n // Build property schema from database, merging with file schema for fields not in DB\n // Use the schema property name (resolvedPropertyName) even if DB has different name (renamed)\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string; _dbId?: number } = {\n ...schemaFromFile, // Start with file schema (has all fields like storageType, etc.)\n id: propertyRecord.schemaFileId || propertyRecord.id?.toString(), // id should be schemaFileId (string), not database ID\n _dbId: propertyRecord.id, // Store database integer ID separately\n name: resolvedPropertyName, // Use schema name, not DB name (for renamed properties)\n dataType: propertyRecord.dataType as any,\n modelId: propertyRecord.modelId,\n modelName,\n refModelId: propertyRecord.refModelId || undefined,\n refValueType: (propertyRecord.refValueType as any) || undefined,\n required: (propertyRecord as { required?: boolean }).required ?? undefined,\n // Include schemaFileId from database as _propertyFileId for ModelProperty.create()\n _propertyFileId: propertyRecord.schemaFileId || undefined,\n }\n \n // If refModelId is set, try to get the refModelName\n if (propertyRecord.refModelId) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.id, propertyRecord.refModelId))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n propertySchema.refModelName = refModelRecords[0].name\n propertySchema.ref = refModelRecords[0].name\n }\n } else if (schemaFromFile?.ref) {\n // If refModelId is not set but schema file has ref, resolve it from the database\n // This handles cases where the property was just created and refModelId hasn't been set yet\n propertySchema.ref = schemaFromFile.ref\n propertySchema.refModelName = schemaFromFile.ref\n \n // Try to resolve refModelId from the database using the model name\n try {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n }\n } catch (error) {\n // Ignore errors - model might not exist yet\n }\n }\n \n return propertySchema\n }\n }\n }\n } catch (error) {\n // Database not available or error - fall through to schema file lookup\n }\n \n // Fall back to schema file lookup\n const schemaFromFile = schema[resolvedPropertyName]\n if (schemaFromFile) {\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string } = { ...schemaFromFile, name: resolvedPropertyName }\n \n // If schema file has id as a string (propertyFileId), set it as _propertyFileId\n // This handles cases where the property hasn't been saved to the database yet\n if (typeof schemaFromFile.id === 'string') {\n propertySchema._propertyFileId = schemaFromFile.id\n }\n \n // If the schema file has ref but no refModelId, try to resolve it from the database\n if (schemaFromFile.ref && !propertySchema.refModelId) {\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n propertySchema.refModelName = schemaFromFile.ref\n }\n }\n } catch (error) {\n // Ignore errors - model might not exist yet or database not available\n }\n }\n \n return propertySchema\n }\n return undefined\n}\n"],"names":["modelPropertiesToObject","resolveStorageNameToSchemaName","BaseDb","modelsTable","eq","properties","and"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;AACI,MAAM,iBAAiB,GAAG,OAC/B,SAAiB,EACjB,YAAoB,KAC8D;;AAElF,IAAA,MAAM,QAAQ,GAAG,MAAM,oDAAO,qBAAgB,8CAAC;AAC/C,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ;AAC1B,IAAA,MAAM,SAAS,GAAG,MAAM,oDAAO,sBAAkB,KAAC;AAClD,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS;IAC5B,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC;IAEnD,IAAI,CAAC,KAAK,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gBAAA,MAAM,EAAE,GAAGD,eAAM,CAAC,QAAQ,EAAE;gBAC5B,IAAI,EAAE,EAAE;oBACN,MAAM,eAAe,GAAG,MAAM;AAC3B,yBAAA,MAAM;yBACN,IAAI,CAACC,eAAW;yBAChB,KAAK,CAACC,aAAE,CAACD,eAAW,CAAC,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC;yBAC9C,KAAK,CAAC,CAAC,CAAC;AAEX,oBAAA,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;wBACvD,cAAc,CAAC,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE;AACjD,wBAAA,cAAc,CAAC,YAAY,GAAG,cAAc,CAAC,GAAG;oBAClD;gBACF;YACF;YAAE,OAAO,KAAK,EAAE;;YAEhB;QACF;AAEA,QAAA,OAAO,cAAc;IACvB;AACA,IAAA,OAAO,SAAS;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"property-D4IB0zBz.js","sources":["../../../src/helpers/property.ts"],"sourcesContent":["import { Static } from '@sinclair/typebox'\nimport { TProperty } from '@/Schema'\n// Dynamic import to break circular dependency: Model -> ... -> helpers/property -> Model\n// import { Model } from '@/Model/Model'\nimport pluralize from 'pluralize'\nimport { resolveStorageNameToSchemaName } from '@/helpers/metadataPropertyNames'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, properties, PropertyType } from '@/seedSchema'\nimport { eq, and } from 'drizzle-orm'\nimport { modelPropertiesToObject } from '@/helpers/model'\n\n// Re-export everything from property/index.ts to make it available when importing from helpers/property\nexport * from './property/index'\n\n/**\n * Gets the propertyRecordSchema object for a given model and property name.\n * \n * The propertyRecordSchema is the property definition object that contains\n * information about the property's data type, storage configuration, and\n * relationship details (for Relation and List types).\n * \n * This function first checks the database for property definitions (which may\n * have been edited), then falls back to schema files. This ensures that\n * edited properties persist across page reloads.\n * \n * This function handles property names that end with 'Id' or 'Ids' by automatically\n * looking up the base property name in the schema (e.g., 'authorId' -> 'author',\n * 'tagIds' -> 'tags').\n * \n * @param modelName - The name of the model (e.g., 'Article', 'Author')\n * @param propertyName - The name of the property (e.g., 'title', 'author', 'authorId', 'tags', 'tagIds')\n * @returns The propertyRecordSchema object (TProperty with optional _propertyFileId) or undefined if not found\n * \n * @example\n * ```typescript\n * const schema = await getPropertySchema('Article', 'title')\n * // Returns: { dataType: 'Text', ... }\n * \n * const relationSchema = await getPropertySchema('Article', 'author')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * \n * // Also works with Id/Ids suffixes\n * const relationSchemaById = await getPropertySchema('Article', 'authorId')\n * // Returns: { dataType: 'Relation', ref: 'Author', ... }\n * ```\n */\nexport const getPropertySchema = async (\n modelName: string,\n propertyName: string,\n): Promise<(Static<typeof TProperty> & { _propertyFileId?: string }) | undefined> => {\n // Dynamic import to break circular dependency\n const modelMod = await import('../Model/Model')\n const { Model } = modelMod\n const schemaMod = await import('../Schema/Schema')\n const { Schema } = schemaMod\n const model = await Model.getByNameAsync(modelName)\n\n if (!model) {\n return undefined\n }\n \n // Get the original schema from Schema instance context (has ref fields from schema file)\n // This is more reliable than modelPropertiesToObject which depends on ModelProperty instances\n let schema: { [propertyName: string]: any } = {}\n try {\n const schemaName = model.schemaName\n if (schemaName) {\n const schemaInstance = Schema.create(schemaName, {\n waitForReady: false,\n }) as import('@/Schema/Schema').Schema\n const schemaContext = schemaInstance.getService().getSnapshot().context\n if (schemaContext.models && schemaContext.models[modelName]) {\n // Get properties from Schema context (original schema file data)\n const modelDef = schemaContext.models[modelName]\n schema = modelDef.properties || {}\n }\n }\n } catch (error) {\n // Fall through to modelPropertiesToObject\n }\n \n // Fallback to modelPropertiesToObject if Schema context doesn't have the data\n if (Object.keys(schema).length === 0) {\n const properties = model.properties || []\n if (properties.length === 0) {\n return undefined\n }\n schema = modelPropertiesToObject(properties)\n }\n \n // Helper to resolve property name (handles Id/Ids suffixes)\n const resolvePropertyName = (propName: string): string | undefined => {\n // First, try direct lookup\n if (schema[propName]) {\n return propName\n }\n\n // List-of-relation storage name (e.g. authorIdentityIds) -> schema key (authors)\n const listSchemaKey = resolveStorageNameToSchemaName(schema, propName)\n if (listSchemaKey && schema[listSchemaKey]) {\n return listSchemaKey\n }\n\n // Handle properties ending with 'Id' or 'Ids'\n let propertyNameWithoutId: string | undefined\n \n if (propName.endsWith('Id')) {\n propertyNameWithoutId = propName.slice(0, -2)\n } else if (propName.endsWith('Ids')) {\n propertyNameWithoutId = propName.slice(0, -3)\n propertyNameWithoutId = pluralize(propertyNameWithoutId)\n }\n \n if (propertyNameWithoutId && schema[propertyNameWithoutId]) {\n return propertyNameWithoutId\n }\n \n return undefined\n }\n \n const resolvedPropertyName = resolvePropertyName(propertyName)\n if (!resolvedPropertyName) {\n return undefined\n }\n \n // Try to get property from database first (may have edited values)\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n // Find the model in the database\n const modelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, modelName))\n .limit(1)\n \n if (modelRecords.length > 0) {\n const modelRecord = modelRecords[0]\n \n // Find the property in the database by name\n let propertyRecords = await db\n .select()\n .from(properties)\n .where(\n and(\n eq(properties.name, resolvedPropertyName),\n eq(properties.modelId, modelRecord.id!),\n ),\n )\n .limit(1)\n \n // If not found by name, check for renamed properties (orphaned DB properties)\n if (propertyRecords.length === 0) {\n // Get all properties for this model\n const allDbProperties = await db\n .select()\n .from(properties)\n .where(eq(properties.modelId, modelRecord.id!))\n \n // Get all schema property names to identify orphaned properties\n const schemaPropertyNames = new Set(Object.keys(schema))\n \n // Get the schema property definition to match characteristics\n const schemaPropertyDef = schema[resolvedPropertyName]\n \n if (schemaPropertyDef) {\n // Find orphaned properties (don't match any schema property name) that match characteristics\n const orphanedProperties = allDbProperties.filter((p: PropertyType) => \n !schemaPropertyNames.has(p.name) && // Doesn't match any schema property name\n p.dataType === schemaPropertyDef.dataType // Same dataType\n )\n \n // If there's exactly one orphaned property with matching characteristics, it's likely the renamed property\n // We can also match by refModelId if it's a relation\n if (orphanedProperties.length > 0) {\n let matchedProperty = orphanedProperties[0]\n \n // If it's a relation, try to match by refModelId\n if (schemaPropertyDef.ref) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaPropertyDef.ref))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n const expectedRefModelId = refModelRecords[0].id\n const matchingByRef = orphanedProperties.find((p: PropertyType) => p.refModelId === expectedRefModelId)\n if (matchingByRef) {\n matchedProperty = matchingByRef\n }\n }\n } else {\n // For non-relation properties, prefer ones without refModelId\n const withoutRef = orphanedProperties.find((p: PropertyType) => p.refModelId === null)\n if (withoutRef) {\n matchedProperty = withoutRef\n }\n }\n \n propertyRecords = [matchedProperty]\n }\n }\n }\n \n if (propertyRecords.length > 0) {\n const propertyRecord = propertyRecords[0]\n \n // Get the base schema from file to merge with database values\n // Use the schema object created earlier, not model.schema (which doesn't exist)\n const schemaFromFile = schema[resolvedPropertyName]\n \n // Build property schema from database, merging with file schema for fields not in DB\n // Use the schema property name (resolvedPropertyName) even if DB has different name (renamed)\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string; _dbId?: number } = {\n ...schemaFromFile, // Start with file schema (has all fields like storageType, etc.)\n id: propertyRecord.schemaFileId || propertyRecord.id?.toString(), // id should be schemaFileId (string), not database ID\n _dbId: propertyRecord.id, // Store database integer ID separately\n name: resolvedPropertyName, // Use schema name, not DB name (for renamed properties)\n dataType: propertyRecord.dataType as any,\n modelId: propertyRecord.modelId,\n modelName,\n refModelId: propertyRecord.refModelId || undefined,\n refValueType: (propertyRecord.refValueType as any) || undefined,\n required: (propertyRecord as { required?: boolean }).required ?? undefined,\n // Include schemaFileId from database as _propertyFileId for ModelProperty.create()\n _propertyFileId: propertyRecord.schemaFileId || undefined,\n }\n \n // If refModelId is set, try to get the refModelName\n if (propertyRecord.refModelId) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.id, propertyRecord.refModelId))\n .limit(1)\n \n if (refModelRecords.length > 0) {\n propertySchema.refModelName = refModelRecords[0].name\n propertySchema.ref = refModelRecords[0].name\n }\n } else if (schemaFromFile?.ref) {\n // If refModelId is not set but schema file has ref, resolve it from the database\n // This handles cases where the property was just created and refModelId hasn't been set yet\n propertySchema.ref = schemaFromFile.ref\n propertySchema.refModelName = schemaFromFile.ref\n \n // Try to resolve refModelId from the database using the model name\n try {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n }\n } catch (error) {\n // Ignore errors - model might not exist yet\n }\n }\n \n return propertySchema\n }\n }\n }\n } catch (error) {\n // Database not available or error - fall through to schema file lookup\n }\n \n // Fall back to schema file lookup\n const schemaFromFile = schema[resolvedPropertyName]\n if (schemaFromFile) {\n const propertySchema: Static<typeof TProperty> & { _propertyFileId?: string } = { ...schemaFromFile, name: resolvedPropertyName }\n \n // If schema file has id as a string (propertyFileId), set it as _propertyFileId\n // This handles cases where the property hasn't been saved to the database yet\n if (typeof schemaFromFile.id === 'string') {\n propertySchema._propertyFileId = schemaFromFile.id\n }\n \n // If the schema file has ref but no refModelId, try to resolve it from the database\n if (schemaFromFile.ref && !propertySchema.refModelId) {\n try {\n const db = BaseDb.getAppDb()\n if (db) {\n const refModelRecords = await db\n .select()\n .from(modelsTable)\n .where(eq(modelsTable.name, schemaFromFile.ref))\n .limit(1)\n \n if (refModelRecords.length > 0 && refModelRecords[0].id) {\n propertySchema.refModelId = refModelRecords[0].id\n propertySchema.refModelName = schemaFromFile.ref\n }\n }\n } catch (error) {\n // Ignore errors - model might not exist yet or database not available\n }\n }\n \n return propertySchema\n }\n return undefined\n}\n"],"names":["modelPropertiesToObject","resolveStorageNameToSchemaName","BaseDb","modelsTable","e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+
var query = require('@seedprotocol/query');
|
|
5
|
+
var main_cjs = require('./index-BD1b6zAi.js');
|
|
5
6
|
var drizzleOrm = require('drizzle-orm');
|
|
6
7
|
var eas$1 = require('@seedprotocol/eas');
|
|
7
8
|
var pluralize = require('pluralize');
|
|
8
|
-
var eas = require('./eas-
|
|
9
|
+
var eas = require('./eas-BJ8FtbU9.js');
|
|
9
10
|
require('immer');
|
|
10
11
|
require('reflect-metadata');
|
|
11
12
|
require('xstate');
|
|
@@ -26,7 +27,6 @@ require('@libsql/client');
|
|
|
26
27
|
require('drizzle-orm/libsql');
|
|
27
28
|
require('drizzle-orm/libsql/migrator');
|
|
28
29
|
require('js-yaml');
|
|
29
|
-
require('@seedprotocol/webpack');
|
|
30
30
|
require('child_process');
|
|
31
31
|
require('@seedprotocol/arweave/node');
|
|
32
32
|
require('@seedprotocol/eas/node');
|
|
@@ -36,7 +36,7 @@ require('@seedprotocol/eas/node');
|
|
|
36
36
|
const schemaStringToModelRecord = new Map();
|
|
37
37
|
const getModelSchemas = async () => {
|
|
38
38
|
// Dynamic import to break circular dependency
|
|
39
|
-
const modelMod = await Promise.resolve().then(function () { return require('./index-
|
|
39
|
+
const modelMod = await Promise.resolve().then(function () { return require('./index-BD1b6zAi.js'); }).then(function (n) { return n.Model$1; });
|
|
40
40
|
const { Model } = modelMod;
|
|
41
41
|
const allModels = await Model.all();
|
|
42
42
|
const modelRecords = [];
|
|
@@ -245,25 +245,24 @@ const createMetadataRecordsForStorageTransactionId = async (storageTransactionId
|
|
|
245
245
|
return;
|
|
246
246
|
}
|
|
247
247
|
// Validate and parse decodedDataJson
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
if (!Array.isArray(parsedData) || parsedData.length === 0 || !parsedData[0]?.value) {
|
|
261
|
-
console.warn('[item/events] [syncDbWithEas] invalid decodedDataJson structure for storageTransactionIdProperty: ', storageTransactionIdProperty.id);
|
|
248
|
+
const parsed = query.parseEasPropertyMetadata(storageTransactionIdProperty.decodedDataJson);
|
|
249
|
+
if (!parsed.ok) {
|
|
250
|
+
if (parsed.reason === 'empty') {
|
|
251
|
+
console.warn('[item/events] [syncDbWithEas] empty decodedDataJson for storageTransactionIdProperty: ', storageTransactionIdProperty.id);
|
|
252
|
+
}
|
|
253
|
+
else if (parsed.reason === 'parse') {
|
|
254
|
+
console.warn('[item/events] [syncDbWithEas] failed to parse decodedDataJson for storageTransactionIdProperty: ', storageTransactionIdProperty.id, parsed.error);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
console.warn('[item/events] [syncDbWithEas] invalid decodedDataJson structure for storageTransactionIdProperty: ', storageTransactionIdProperty.id);
|
|
258
|
+
}
|
|
262
259
|
return;
|
|
263
260
|
}
|
|
264
|
-
const attestationData =
|
|
261
|
+
const attestationData = parsed.metadata;
|
|
265
262
|
lodashEs.camelCase(attestationData.name);
|
|
266
|
-
const propertyValue = attestationData.value
|
|
263
|
+
const propertyValue = typeof attestationData.value === 'string'
|
|
264
|
+
? attestationData.value
|
|
265
|
+
: JSON.stringify(attestationData.value);
|
|
267
266
|
const itemStorageProperties = new Map();
|
|
268
267
|
for (const [_propertyName, propertyDef] of Object.entries(modelSchema)) {
|
|
269
268
|
if (propertyDef?.storageType && propertyDef.storageType === 'ItemStorage') {
|
|
@@ -314,7 +313,7 @@ let saveEasPropertiesDbChain = Promise.resolve();
|
|
|
314
313
|
const saveEasPropertiesToDbBody = async ({ itemProperties, itemSeeds, }) => {
|
|
315
314
|
const propertyUids = itemProperties.map((property) => property.id);
|
|
316
315
|
// Dynamic import to break circular dependency
|
|
317
|
-
const modelMod = await Promise.resolve().then(function () { return require('./index-
|
|
316
|
+
const modelMod = await Promise.resolve().then(function () { return require('./index-BD1b6zAi.js'); }).then(function (n) { return n.Model$1; });
|
|
318
317
|
const { Model } = modelMod;
|
|
319
318
|
const allModels = await Model.all();
|
|
320
319
|
const models = Object.fromEntries(allModels.map(m => [m.modelName, m]));
|
|
@@ -349,24 +348,21 @@ const saveEasPropertiesToDbBody = async ({ itemProperties, itemSeeds, }) => {
|
|
|
349
348
|
const property = newProperties[i];
|
|
350
349
|
const propertyLocalId = main_cjs.generateId();
|
|
351
350
|
// Validate and parse decodedDataJson
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
if (!Array.isArray(parsedData) || parsedData.length === 0 || !parsedData[0]?.value) {
|
|
365
|
-
console.warn('[item/events] [syncDbWithEas] invalid decodedDataJson structure for property: ', property.id);
|
|
351
|
+
const parsed = query.parseEasPropertyMetadata(property.decodedDataJson);
|
|
352
|
+
if (!parsed.ok) {
|
|
353
|
+
if (parsed.reason === 'empty') {
|
|
354
|
+
console.warn('[item/events] [syncDbWithEas] empty decodedDataJson for property: ', property.id);
|
|
355
|
+
}
|
|
356
|
+
else if (parsed.reason === 'parse') {
|
|
357
|
+
console.warn('[item/events] [syncDbWithEas] failed to parse decodedDataJson for property: ', property.id, parsed.error);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
console.warn('[item/events] [syncDbWithEas] invalid decodedDataJson structure for property: ', property.id);
|
|
361
|
+
}
|
|
366
362
|
continue;
|
|
367
363
|
}
|
|
368
|
-
const
|
|
369
|
-
let propertyNameSnake =
|
|
364
|
+
const propertyMetadata = parsed.metadata;
|
|
365
|
+
let propertyNameSnake = propertyMetadata.name;
|
|
370
366
|
if (!propertyNameSnake) {
|
|
371
367
|
console.warn('[item/events] [syncDbWithEas] no propertyName found for property: ', property);
|
|
372
368
|
continue;
|
|
@@ -386,38 +382,38 @@ const saveEasPropertiesToDbBody = async ({ itemProperties, itemSeeds, }) => {
|
|
|
386
382
|
propertyNameSnake !== 'storage_transaction_id' &&
|
|
387
383
|
propertyNameSnake !== 'storage_provider_transaction_id') {
|
|
388
384
|
isRelation = true;
|
|
389
|
-
if (Array.isArray(
|
|
385
|
+
if (Array.isArray(propertyMetadata.value)) {
|
|
390
386
|
isList = true;
|
|
391
387
|
refValueType = 'list';
|
|
392
|
-
const result =
|
|
388
|
+
const result = query.parseEasRelationPropertyName(propertyNameSnake);
|
|
393
389
|
if (result) {
|
|
394
390
|
propertyNameSnake = result.propertyName;
|
|
395
391
|
refSeedType = result.modelName;
|
|
396
392
|
}
|
|
397
|
-
|
|
393
|
+
propertyMetadata.value.forEach((value) => {
|
|
398
394
|
relatedSeedUids.add(value);
|
|
399
395
|
});
|
|
400
396
|
}
|
|
401
397
|
if (!isList) {
|
|
402
|
-
if (relationValuesToExclude.includes(
|
|
398
|
+
if (relationValuesToExclude.includes(propertyMetadata.value)) {
|
|
403
399
|
continue;
|
|
404
400
|
}
|
|
405
|
-
relatedSeedUids.add(
|
|
401
|
+
relatedSeedUids.add(propertyMetadata.value);
|
|
406
402
|
}
|
|
407
403
|
}
|
|
408
|
-
let propertyValue =
|
|
404
|
+
let propertyValue = propertyMetadata.value;
|
|
409
405
|
if (typeof propertyValue !== 'string') {
|
|
410
406
|
propertyValue = JSON.stringify(propertyValue);
|
|
411
407
|
}
|
|
412
408
|
if (isRelation && !isList) {
|
|
413
|
-
const relatedSeed = itemSeeds.find((seed) => seed.id ===
|
|
409
|
+
const relatedSeed = itemSeeds.find((seed) => seed.id === propertyMetadata.value);
|
|
414
410
|
if (relatedSeed && relatedSeed.schema && relatedSeed.schema.schemaNames) {
|
|
415
411
|
refSeedType = relatedSeed.schema.schemaNames[0].name;
|
|
416
412
|
refSchemaUid = relatedSeed.schemaId;
|
|
417
413
|
}
|
|
418
414
|
}
|
|
419
415
|
if (isRelation && isList) {
|
|
420
|
-
const relatedSeeds = itemSeeds.filter((seed) =>
|
|
416
|
+
const relatedSeeds = itemSeeds.filter((seed) => propertyMetadata.value.includes(seed.id));
|
|
421
417
|
if (relatedSeeds && relatedSeeds.length > 0) {
|
|
422
418
|
refSeedType = relatedSeeds[0].schema.schemaNames[0].name;
|
|
423
419
|
refSchemaUid = relatedSeeds[0].schemaId;
|
|
@@ -425,7 +421,7 @@ const saveEasPropertiesToDbBody = async ({ itemProperties, itemSeeds, }) => {
|
|
|
425
421
|
}
|
|
426
422
|
const propertyName = lodashEs.camelCase(propertyNameSnake);
|
|
427
423
|
propertyValue = main_cjs.escapeSqliteString(propertyValue);
|
|
428
|
-
const easDataType =
|
|
424
|
+
const easDataType = propertyMetadata.type;
|
|
429
425
|
const versionUid = property.refUID;
|
|
430
426
|
const versionLocalId = versionUidToLocalId.get(versionUid);
|
|
431
427
|
const attestationCreatedAt = property.timeCreated * 1000;
|
|
@@ -504,8 +500,9 @@ const getRelatedSeedsAndVersions = async () => {
|
|
|
504
500
|
},
|
|
505
501
|
},
|
|
506
502
|
});
|
|
503
|
+
const canonicalRelatedProperties = eas$1.pickLatestPropertyAttestationsByRefAndSchema(itemProperties);
|
|
507
504
|
await saveEasPropertiesToDb({
|
|
508
|
-
itemProperties,
|
|
505
|
+
itemProperties: canonicalRelatedProperties,
|
|
509
506
|
itemSeeds,
|
|
510
507
|
});
|
|
511
508
|
};
|
|
@@ -583,7 +580,7 @@ const runSyncFromEas = async (options) => {
|
|
|
583
580
|
await getRelatedSeedsAndVersions();
|
|
584
581
|
main_cjs.scheduleBulkFilesDownloadFromEasSync(addresses);
|
|
585
582
|
try {
|
|
586
|
-
const itemMod = await Promise.resolve().then(function () { return require('./index-
|
|
583
|
+
const itemMod = await Promise.resolve().then(function () { return require('./index-BD1b6zAi.js'); }).then(function (n) { return n.Item$1; });
|
|
587
584
|
await itemMod.Item.rehydrateCachedItemsFromDbAfterEasSync();
|
|
588
585
|
}
|
|
589
586
|
catch (err) {
|
|
@@ -593,4 +590,4 @@ const runSyncFromEas = async (options) => {
|
|
|
593
590
|
};
|
|
594
591
|
|
|
595
592
|
exports.runSyncFromEas = runSyncFromEas;
|
|
596
|
-
//# sourceMappingURL=syncDbWithEas-
|
|
593
|
+
//# sourceMappingURL=syncDbWithEas-BYvFJc7N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncDbWithEas-BYvFJc7N.js","sources":["../../../src/db/read/getModelSchemas.ts","../../../src/db/write/createSeeds.ts","../../../src/db/write/updateSeedRevokedAt.ts","../../../src/events/item/syncDbWithEas.ts"],"sourcesContent":["// Dynamic import to break circular dependency: Model -> BaseItem -> ... -> getModelSchemas -> Model\n// import { Model } from '@/Model/Model'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { models as modelsTable, modelUids } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\nimport pluralize from 'pluralize'\nimport { toSnakeCase } from '@/helpers'\n\ntype ModelRecord = {\n id: number\n name: string\n uid: string | null\n tableName?: string\n}\n\nconst schemaStringToModelRecord = new Map<string, ModelRecord>()\n\ntype GetModelSchemasReturn = {\n schemaStringToModelRecord: Map<string, ModelRecord>\n modelRecords: ModelRecord[]\n}\n\ntype GetModelSchemas = () => Promise<GetModelSchemasReturn>\n\nexport const getModelSchemas: GetModelSchemas = async () => {\n // Dynamic import to break circular dependency\n const modelMod = await import('../../Model/Model')\n const { Model } = modelMod\n const allModels = await Model.all()\n const modelRecords: ModelRecord[] = []\n\n const appDb = BaseDb.getAppDb()\n\n for (const model of allModels) {\n const modelName = model.modelName\n if (!modelName) continue\n const foundModelQuery = await appDb\n .select({\n id: modelsTable.id,\n name: modelsTable.name,\n uid: modelUids.uid,\n })\n .from(modelsTable)\n .leftJoin(modelUids, eq(modelsTable.id, modelUids.modelId))\n .where(eq(modelsTable.name, modelName))\n .limit(1)\n\n if (!foundModelQuery[0]) {\n console.error(\n `[item/events] [syncDbWithEas] model ${modelName} not found in SDK DB`,\n )\n continue\n }\n\n const foundModel: ModelRecord = {\n id: foundModelQuery[0].id,\n name: foundModelQuery[0].name,\n uid: foundModelQuery[0].uid,\n tableName: pluralize(foundModelQuery[0].name).toLowerCase(),\n }\n\n modelRecords.push(foundModel)\n\n if (modelName === 'Seed') {\n continue\n }\n\n const schemaString = `bytes32 ${toSnakeCase(modelName)}`\n\n schemaStringToModelRecord.set(schemaString, foundModel)\n }\n\n return {\n schemaStringToModelRecord,\n modelRecords,\n }\n}\n","import { seeds, SeedType } from '@/seedSchema'\nimport { BaseDb } from '@/db/Db/BaseDb'\n\ntype CreateSeeds = (newSeeds: Partial<SeedType>[]) => Promise<string[]>\n\nexport const createSeeds: CreateSeeds = async (\n newSeeds: Partial<SeedType>[],\n) => {\n const appDb = BaseDb.getAppDb()\n\n const results = await appDb\n .insert(seeds)\n .values(newSeeds)\n .returning({ uid: seeds.uid })\n\n const newUids = results.reduce((acc: string[], result: { uid: string | null }) => {\n if (result.uid) {\n acc.push(result.uid)\n }\n return acc\n }, [] as string[])\n\n return newUids\n}\n","import { BaseDb } from '@/db/Db/BaseDb'\nimport { seeds } from '@/seedSchema'\nimport { eq } from 'drizzle-orm'\n\ntype UpdateSeedRevokedAtProps = {\n seedLocalId: string\n revokedAt: number\n}\n\n/**\n * Sets revokedAt timestamp on a seed record after attestations have been revoked on EAS.\n */\nexport const updateSeedRevokedAt = async ({\n seedLocalId,\n revokedAt,\n}: UpdateSeedRevokedAtProps): Promise<void> => {\n if (!seedLocalId) {\n return\n }\n\n const appDb = BaseDb.getAppDb()\n\n await appDb\n .update(seeds)\n .set({\n revokedAt,\n updatedAt: Date.now(),\n })\n .where(eq(seeds.localId, seedLocalId))\n}\n","import { camelCase, startCase } from 'lodash-es'\nimport { Attestation, SchemaWhereInput } from '@seedprotocol/eas'\nimport {\n parseEasPropertyMetadata,\n parseEasRelationPropertyName,\n} from '@seedprotocol/query'\nimport {\n metadata,\n MetadataType,\n modelUids,\n seeds,\n SeedType,\n versions,\n} from '@/seedSchema'\nimport { and, eq, inArray, sql } from 'drizzle-orm'\nimport {\n generateId,\n} from '@/helpers'\nimport { modelPropertiesToObject } from '@/helpers/model'\nimport {\n GET_PROPERTIES,\n GET_SEEDS,\n GET_VERSIONS,\n} from '@seedprotocol/eas'\nimport { escapeSqliteString, getAllAddressesFromDb, getPropertyIdForModelAndName } from '@/helpers/db'\n// Dynamic import to break circular dependency: Model -> BaseItem -> ... -> syncDbWithEas -> Model\n// import { Model } from '@/Model/Model'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { getModelSchemas } from '@/db/read/getModelSchemas'\nimport { ModelSchema, PropertyType } from '@/types'\nimport { createSeeds } from '@/db/write/createSeeds'\nimport { updateSeedRevokedAt } from '@/db/write/updateSeedRevokedAt'\nimport { setSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'\nimport { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'\nimport {\n getItemPropertiesFromEas,\n getItemVersionsFromEas,\n getModelSchemasFromEas,\n getSeedsFromSchemaUids,\n} from '@/eas'\nimport { pickLatestPropertyAttestationsByRefAndSchema } from '@/helpers/easPropertyCanonical'\nimport { getGetAdditionalSyncAddresses } from '@/helpers/publishConfig'\nimport { scheduleBulkFilesDownloadFromEasSync } from '@/events/files/download'\nimport { eventEmitter } from '@/eventBus'\nimport { EAS_SEED_DATA_SYNCED_TO_DB_EVENT } from '@/helpers/constants'\n\nconst relationValuesToExclude = [\n '0x0000000000000000000000000000000000000000000000000000000000000020',\n]\n\n\nconst seedUidToLocalId = new Map<string, string>()\nconst seedUidToModelType = new Map<string, string>()\nconst relatedSeedUids = new Set<string>()\n\nconst versionUidToLocalId = new Map<string, string>()\nconst versionUidToSeedUid = new Map<string, string>()\n\nconst propertyUidToLocalId = new Map<string, string>()\n\ntype SaveEasSeedsToDbProps = {\n itemSeeds: Attestation[]\n}\n\ntype SaveEasSeedsToDbReturn = {\n seedUids: string[]\n}\n\ntype SaveEasSeedsToDb = (\n props: SaveEasSeedsToDbProps,\n) => Promise<SaveEasSeedsToDbReturn>\n\nconst saveEasSeedsToDb: SaveEasSeedsToDb = async ({ itemSeeds }) => {\n const appDb = BaseDb.getAppDb()\n\n const seedUids = itemSeeds.map((seed) => seed.id)\n\n const existingSeedRecordsRows: SeedType[] = await appDb\n .select()\n .from(seeds)\n .where(inArray(seeds.uid, seedUids))\n\n const existingSeedUids = new Set<string>()\n\n if (existingSeedRecordsRows && existingSeedRecordsRows.length > 0) {\n for (const row of existingSeedRecordsRows) {\n if (row.uid) {\n existingSeedUids.add(row.uid)\n if (row.localId) {\n seedUidToLocalId.set(row.uid, row.localId)\n }\n if (row.type) {\n seedUidToModelType.set(row.uid, row.type)\n }\n }\n }\n }\n\n const newSeeds = itemSeeds.filter((seed) => !existingSeedUids.has(seed.id))\n\n // Update existing seeds when attestations are revoked on EAS\n const seedByUid = new Map(itemSeeds.map((s) => [s.id, s]))\n for (const row of existingSeedRecordsRows) {\n if (!row.uid || !row.localId) continue\n const attestation = seedByUid.get(row.uid)\n if (!attestation?.revoked) continue\n if (row.revokedAt != null) continue\n const revokedAt =\n attestation.revocationTime > 0\n ? attestation.revocationTime\n : Math.floor(Date.now() / 1000)\n await updateSeedRevokedAt({ seedLocalId: row.localId, revokedAt })\n }\n\n if (newSeeds.length === 0) {\n return { seedUidToLocalId, seedUids }\n }\n\n const newSeedsData: Partial<SeedType>[] = []\n\n for (let i = 0; i < newSeeds.length; i++) {\n const seed = newSeeds[i]\n seedUidToModelType.set(seed.id, seed.schema.schemaNames[0].name)\n const seedLocalId = generateId()\n seedUidToLocalId.set(seed.id, seedLocalId)\n\n const attestationRaw = escapeSqliteString(JSON.stringify(seed))\n const revokedAt =\n seed.revoked && seed.revocationTime != null && seed.revocationTime > 0\n ? seed.revocationTime\n : seed.revoked\n ? Math.floor(Date.now() / 1000)\n : undefined\n\n newSeedsData.push({\n localId: seedLocalId,\n uid: seed.id,\n schemaUid: seed.schemaId,\n type: seed.schema.schemaNames[0].name,\n publisher: seed.attester,\n createdAt: Date.now(),\n attestationCreatedAt: seed.timeCreated * 1000,\n attestationRaw,\n ...(revokedAt !== undefined && { revokedAt }),\n })\n\n seedUidToLocalId.set(seed.id, seedLocalId)\n }\n\n const newSeedUids = await createSeeds(newSeedsData)\n\n return { seedUids: newSeedUids }\n}\n\ntype SaveEasVersionsToDbParams = {\n itemVersions: Attestation[]\n}\n\ntype SaveEasVersionsToDb = (\n props: SaveEasVersionsToDbParams,\n) => Promise<SaveEasVersionsToDbReturn>\n\ntype SaveEasVersionsToDbReturn = {\n versionUids: string[]\n}\n\nconst saveEasVersionsToDb: SaveEasVersionsToDb = async ({ itemVersions }) => {\n const versionUids = itemVersions.map((version) => version.id)\n\n const appDb = BaseDb.getAppDb()\n\n const existingVersionRecordsRows: MetadataType[] = await appDb\n .select()\n .from(versions)\n .where(inArray(versions.uid, versionUids))\n\n const existingVersionUids = new Set<string>()\n\n if (existingVersionRecordsRows && existingVersionRecordsRows.length > 0) {\n for (const row of existingVersionRecordsRows) {\n if (row.uid) {\n existingVersionUids.add(row.uid)\n if (row.localId) {\n versionUidToLocalId.set(row.uid, row.localId)\n }\n if (row.seedUid) {\n versionUidToSeedUid.set(row.uid, row.seedUid)\n }\n }\n }\n }\n\n const newVersions = itemVersions.filter(\n (version) => !existingVersionUids.has(version.id),\n )\n\n if (newVersions.length === 0) {\n return { versionUidToLocalId, versionUids }\n }\n\n let insertVersionsQuery = `INSERT INTO versions (local_id, uid, seed_uid, seed_local_id, seed_type, created_at,\n attestation_created_at,\n attestation_raw, publisher)\n VALUES `\n\n for (let i = 0; i < newVersions.length; i++) {\n const version = newVersions[i]\n versionUidToSeedUid.set(version.id, version.refUID)\n const versionLocalId = generateId()\n versionUidToLocalId.set(version.id, versionLocalId)\n\n const seedUid = versionUidToSeedUid.get(version.id)\n const seedLocalId = seedUidToLocalId.get(seedUid!)\n const seedType = seedUidToModelType.get(seedUid!)\n const attestationRaw = escapeSqliteString(JSON.stringify(version))\n const publisher = escapeSqliteString(version.attester ?? '')\n\n const valuesString = `('${versionLocalId}', '${version.id}', '${seedUid}', '${seedLocalId}', '${seedType}', ${Date.now()}, ${version.timeCreated * 1000}, '${attestationRaw}', '${publisher}')`\n\n if (i < newVersions.length - 1) {\n insertVersionsQuery += valuesString + ', '\n }\n\n if (i === newVersions.length - 1) {\n insertVersionsQuery += valuesString + ';'\n }\n\n versionUidToLocalId.set(version.id, versionLocalId)\n }\n\n await appDb.run(sql.raw(insertVersionsQuery))\n\n return { versionUids }\n}\n\nconst createMetadataRecordsForStorageTransactionId = async (\n storageTransactionIdProperty: Attestation,\n modelSchema: ModelSchema | undefined,\n) => {\n // Early return if modelSchema is not provided\n if (!modelSchema) {\n console.warn(\n '[item/events] [syncDbWithEas] modelSchema is undefined for storageTransactionIdProperty: ',\n storageTransactionIdProperty.id,\n )\n return\n }\n\n // Validate and parse decodedDataJson\n const parsed = parseEasPropertyMetadata(\n storageTransactionIdProperty.decodedDataJson,\n )\n if (!parsed.ok) {\n if (parsed.reason === 'empty') {\n console.warn(\n '[item/events] [syncDbWithEas] empty decodedDataJson for storageTransactionIdProperty: ',\n storageTransactionIdProperty.id,\n )\n } else if (parsed.reason === 'parse') {\n console.warn(\n '[item/events] [syncDbWithEas] failed to parse decodedDataJson for storageTransactionIdProperty: ',\n storageTransactionIdProperty.id,\n parsed.error,\n )\n } else {\n console.warn(\n '[item/events] [syncDbWithEas] invalid decodedDataJson structure for storageTransactionIdProperty: ',\n storageTransactionIdProperty.id,\n )\n }\n return\n }\n\n const attestationData = parsed.metadata\n const propertyName = camelCase(attestationData.name)\n const propertyValue =\n typeof attestationData.value === 'string'\n ? attestationData.value\n : JSON.stringify(attestationData.value)\n\n const itemStorageProperties = new Map<string, PropertyType>()\n\n for (const [_propertyName, propertyDef] of Object.entries(modelSchema)) {\n if (propertyDef?.storageType && propertyDef.storageType === 'ItemStorage') {\n itemStorageProperties.set(_propertyName, propertyDef)\n }\n }\n\n if (itemStorageProperties.size === 0) {\n return\n }\n\n const appDb = BaseDb.getAppDb()\n\n for (const [_propertyName, propertyDef] of itemStorageProperties.entries()) {\n const existingMetadataRecordRows = await appDb\n .select()\n .from(metadata)\n .where(\n and(\n eq(metadata.propertyName, _propertyName),\n eq(metadata.propertyValue, propertyValue),\n eq(metadata.versionUid, storageTransactionIdProperty.refUID),\n ),\n )\n\n if (existingMetadataRecordRows && existingMetadataRecordRows.length > 0) {\n continue\n }\n\n const seedUid = versionUidToSeedUid.get(\n storageTransactionIdProperty.refUID,\n ) as string\n const seedLocalId = seedUidToLocalId.get(seedUid)\n const versionUid = storageTransactionIdProperty.refUID\n const versionLocalId = versionUidToLocalId.get(versionUid)\n const modelType = seedUidToModelType.get(seedUid)\n const propertyId =\n modelType != null\n ? await getPropertyIdForModelAndName(modelType, _propertyName)\n : null\n\n const propertyLocalId = generateId()\n await appDb.insert(metadata).values({\n localId: propertyLocalId,\n propertyId: propertyId ?? undefined,\n propertyName: _propertyName,\n propertyValue,\n localStorageDir: propertyDef.localStorageDir,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n refValueType: 'file',\n refResolvedValue: `${propertyValue}${propertyDef.filenameSuffix}`,\n modelType: seedUidToModelType.get(seedUid),\n createdAt: Date.now(),\n updatedAt: Date.now(),\n })\n }\n}\n\ntype SaveEasPropertiesToDbParams = {\n itemProperties: Attestation[]\n itemSeeds: Attestation[]\n}\n\ntype SaveEasPropertiesToDbReturn = {\n propertyUids: string[]\n propertyUidToLocalId?: Map<string, string>\n}\n\ntype SaveEasPropertiesToDb = (\n props: SaveEasPropertiesToDbParams,\n) => Promise<SaveEasPropertiesToDbReturn>\n\n/** Serialize property saves: concurrent `runSyncFromEas` used to hit `isSavingToDb` and return `{}` with no insert. */\nlet saveEasPropertiesDbChain: Promise<unknown> = Promise.resolve()\n\nconst saveEasPropertiesToDbBody = async ({\n itemProperties,\n itemSeeds,\n}: SaveEasPropertiesToDbParams): Promise<SaveEasPropertiesToDbReturn> => {\n const propertyUids = itemProperties.map((property) => property.id)\n\n // Dynamic import to break circular dependency\n const modelMod = await import('../../Model/Model')\n const { Model } = modelMod\n const allModels = await Model.all()\n const models = Object.fromEntries(allModels.map(m => [m.modelName!, m]))\n\n const appDb = BaseDb.getAppDb()\n\n const existingMetadataRecordsRows: MetadataType[] = await appDb\n .select()\n .from(metadata)\n .where(inArray(metadata.uid, propertyUids))\n\n const existingPropertyRecordsUids = new Set<string>()\n\n if (existingMetadataRecordsRows && existingMetadataRecordsRows.length > 0) {\n for (const row of existingMetadataRecordsRows) {\n if (row.uid) {\n existingPropertyRecordsUids.add(row.uid)\n if (row.localId) {\n propertyUidToLocalId.set(row.uid, row.localId)\n }\n }\n }\n }\n\n const newProperties = itemProperties.filter(\n (property) => !existingPropertyRecordsUids.has(property.id),\n )\n\n if (newProperties.length === 0) {\n return { propertyUidToLocalId, propertyUids }\n }\n\n let insertPropertiesQuery = `INSERT INTO metadata (local_id, uid, schema_uid, property_id, property_name, property_value,\n eas_data_type, version_uid, version_local_id, seed_uid,\n seed_local_id, model_type, ref_value_type, ref_seed_type,\n ref_schema_uid,\n created_at, attestation_created_at, attestation_raw,\n local_storage_dir, ref_resolved_value, publisher)\n VALUES `\n\n for (let i = 0; i < newProperties.length; i++) {\n const property = newProperties[i]\n const propertyLocalId = generateId()\n \n // Validate and parse decodedDataJson\n const parsed = parseEasPropertyMetadata(property.decodedDataJson)\n if (!parsed.ok) {\n if (parsed.reason === 'empty') {\n console.warn(\n '[item/events] [syncDbWithEas] empty decodedDataJson for property: ',\n property.id,\n )\n } else if (parsed.reason === 'parse') {\n console.warn(\n '[item/events] [syncDbWithEas] failed to parse decodedDataJson for property: ',\n property.id,\n parsed.error,\n )\n } else {\n console.warn(\n '[item/events] [syncDbWithEas] invalid decodedDataJson structure for property: ',\n property.id,\n )\n }\n continue\n }\n\n const propertyMetadata = parsed.metadata\n\n let propertyNameSnake = propertyMetadata.name\n\n if (!propertyNameSnake) {\n console.warn(\n '[item/events] [syncDbWithEas] no propertyName found for property: ',\n property,\n )\n continue\n }\n\n let isRelation = false\n let refValueType\n let refSeedType\n let refSchemaUid\n let refResolvedValue\n let isList = false\n const schemaUid = property.schemaId\n\n setSchemaUidForSchemaDefinition({\n text: propertyNameSnake,\n schemaUid,\n })\n\n if (\n (propertyNameSnake.endsWith('_id') ||\n propertyNameSnake.endsWith('_ids')) &&\n propertyNameSnake !== 'storage_transaction_id' &&\n propertyNameSnake !== 'storage_provider_transaction_id'\n ) {\n isRelation = true\n\n if (Array.isArray(propertyMetadata.value)) {\n isList = true\n refValueType = 'list'\n\n const result = parseEasRelationPropertyName(propertyNameSnake)\n\n if (result) {\n propertyNameSnake = result.propertyName\n refSeedType = result.modelName\n }\n\n propertyMetadata.value.forEach((value: string) => {\n relatedSeedUids.add(value)\n })\n }\n\n if (!isList) {\n if (relationValuesToExclude.includes(propertyMetadata.value as string)) {\n continue\n }\n relatedSeedUids.add(propertyMetadata.value as string)\n }\n }\n\n let propertyValue = propertyMetadata.value\n\n if (typeof propertyValue !== 'string') {\n propertyValue = JSON.stringify(propertyValue)\n }\n\n if (isRelation && !isList) {\n const relatedSeed = itemSeeds.find(\n (seed: Attestation) => seed.id === propertyMetadata.value,\n )\n if (relatedSeed && relatedSeed.schema && relatedSeed.schema.schemaNames) {\n refSeedType = relatedSeed.schema.schemaNames[0].name\n refSchemaUid = relatedSeed.schemaId\n }\n }\n\n if (isRelation && isList) {\n const relatedSeeds = itemSeeds.filter((seed: Attestation) =>\n (propertyMetadata.value as string[]).includes(seed.id),\n )\n if (relatedSeeds && relatedSeeds.length > 0) {\n refSeedType = relatedSeeds[0].schema.schemaNames[0].name\n refSchemaUid = relatedSeeds[0].schemaId\n }\n }\n\n const propertyName = camelCase(propertyNameSnake)\n propertyValue = escapeSqliteString(propertyValue)\n const easDataType = propertyMetadata.type\n const versionUid = property.refUID\n const versionLocalId = versionUidToLocalId.get(versionUid)\n const attestationCreatedAt = property.timeCreated * 1000\n const attestationRaw = escapeSqliteString(JSON.stringify(property))\n const seedUid = versionUidToSeedUid.get(versionUid)\n const seedLocalId = seedUidToLocalId.get(seedUid!)\n const modelType = seedUidToModelType.get(seedUid!)\n\n let localStorageDir\n const modelName = startCase(modelType)\n const model = models[modelName]\n const modelSchema = model?.properties ? modelPropertiesToObject(model.properties) : undefined\n\n if (propertyNameSnake === 'storage_transaction_id') {\n await createMetadataRecordsForStorageTransactionId(property, modelSchema)\n }\n\n const propertyId =\n modelType != null\n ? await getPropertyIdForModelAndName(modelType, propertyName)\n : null\n const propertyIdSql = propertyId != null ? String(propertyId) : 'NULL'\n\n const publisher = escapeSqliteString(property.attester ?? '')\n const valuesString = `('${propertyLocalId}', '${property.id}', \n '${property.schemaId}', ${propertyIdSql}, '${propertyName}', \n '${propertyValue}', '${easDataType}', '${versionUid}', \n '${versionLocalId}', '${seedUid}', '${seedLocalId}', \n '${modelType}', ${refValueType ? `'${refValueType}'` : 'NULL'}, \n ${refSeedType ? `'${refSeedType}'` : 'NULL'},\n ${refSchemaUid ? `'${refSchemaUid}'` : 'NULL'},\n ${Date.now()}, ${attestationCreatedAt}, '${attestationRaw}',\n ${localStorageDir ? `'${localStorageDir}'` : 'NULL'},\n ${refResolvedValue ? `'${refResolvedValue}'` : 'NULL'},\n '${publisher}')`\n\n if (i < newProperties.length - 1) {\n insertPropertiesQuery += valuesString + ', '\n }\n\n if (i === newProperties.length - 1) {\n insertPropertiesQuery += valuesString + ';'\n }\n\n propertyUidToLocalId.set(property.id, propertyLocalId)\n }\n\n if (insertPropertiesQuery.endsWith('VALUES ')) {\n return { propertyUids }\n }\n\n if (insertPropertiesQuery.endsWith(', ')) {\n insertPropertiesQuery = insertPropertiesQuery.slice(0, -2) + ';'\n }\n\n await appDb.run(sql.raw(insertPropertiesQuery))\n\n return { propertyUids }\n}\n\nconst saveEasPropertiesToDb: SaveEasPropertiesToDb = (params) => {\n const next = saveEasPropertiesDbChain.then(() => saveEasPropertiesToDbBody(params))\n saveEasPropertiesDbChain = next.then(\n () => undefined,\n () => undefined,\n )\n return next\n}\n\nconst getRelatedSeedsAndVersions = async () => {\n const queryClient = BaseQueryClient.getQueryClient()\n const easClient = BaseEasClient.getEasClient()\n\n const { itemSeeds } = await easClient.request(GET_SEEDS, {\n where: {\n id: {\n in: Array.from(relatedSeedUids),\n },\n },\n })\n\n await saveEasSeedsToDb({ itemSeeds })\n\n const { itemVersions } = await easClient.request(GET_VERSIONS, {\n where: {\n refUID: {\n in: Array.from(relatedSeedUids),\n },\n },\n })\n\n await saveEasVersionsToDb({ itemVersions })\n\n const relatedVersionUids = itemVersions.map((v) => v.id)\n\n const { itemProperties } = await easClient.request(GET_PROPERTIES, {\n where: {\n refUID: {\n in: relatedVersionUids,\n },\n },\n })\n\n const canonicalRelatedProperties =\n pickLatestPropertyAttestationsByRefAndSchema(itemProperties)\n\n await saveEasPropertiesToDb({\n itemProperties: canonicalRelatedProperties,\n itemSeeds,\n })\n}\n\nexport type SyncFromEasOptions = {\n /** Override addresses to sync. Default: owned + watched from DB. */\n addresses?: string[]\n}\n\n/**\n * Core sync logic: fetches item attestations from EAS for configured models and given addresses,\n * then saves seeds, versions, and properties to the local DB.\n * Uses owned + watched addresses from DB when addresses are not provided.\n */\nexport const runSyncFromEas = async (options?: SyncFromEasOptions): Promise<void> => {\n let addresses = options?.addresses ?? (await getAllAddressesFromDb())\n const additionalGetter = getGetAdditionalSyncAddresses()\n if (additionalGetter) {\n const additional = await additionalGetter()\n if (additional?.length) {\n const seen = new Set(addresses.map((a) => a.toLowerCase()))\n for (const addr of additional) {\n if (addr && !seen.has(addr.toLowerCase())) {\n seen.add(addr.toLowerCase())\n addresses = [...addresses, addr]\n }\n }\n }\n }\n if (!addresses || addresses.length === 0) {\n return\n }\n\n const appDb = BaseDb.getAppDb()\n\n const { schemaStringToModelRecord } = await getModelSchemas()\n\n const modelSchemas = await getModelSchemasFromEas()\n\n const schemaUids: string[] = []\n\n for (const modelSchema of modelSchemas) {\n const foundModel = schemaStringToModelRecord.get(modelSchema.schema)\n\n if (!foundModel) {\n // Skip schemas that don't have a corresponding model in the user's config\n // This can happen with \"bytes32 image\" if there's no Image model defined\n console.warn(\n `[item/events] [syncDbWithEas] Model not found for schema ${modelSchema.schema}, skipping`\n )\n continue\n }\n\n try {\n await appDb\n .insert(modelUids)\n .values({\n modelId: foundModel.id,\n uid: modelSchema.id,\n })\n .onConflictDoNothing()\n } catch (err: unknown) {\n // Model may have been deleted by test teardown or another process; skip to avoid unhandled rejection\n const e = err as { code?: string; rawCode?: number; cause?: { code?: string; rawCode?: number } }\n const code = e?.code ?? e?.rawCode ?? e?.cause?.code ?? e?.cause?.rawCode\n if (code === 'SQLITE_CONSTRAINT_FOREIGNKEY' || code === 787) {\n continue\n }\n throw err\n }\n\n schemaUids.push(modelSchema.id)\n }\n\n // If no schemas were found, skip the rest of the sync process\n // This can happen when models exist but don't have schemas registered in EAS yet\n if (schemaUids.length === 0) {\n return\n }\n\n const itemSeeds = await getSeedsFromSchemaUids({\n schemaUids,\n addresses,\n excludeRevoked: false,\n })\n\n const { seedUids } = await saveEasSeedsToDb({\n itemSeeds,\n })\n\n const itemVersions = await getItemVersionsFromEas({\n seedUids,\n excludeRevoked: false,\n })\n\n const { versionUids } = await saveEasVersionsToDb({\n itemVersions,\n })\n\n const rawProperties = await getItemPropertiesFromEas({\n versionUids,\n excludeRevoked: false,\n })\n const itemProperties = pickLatestPropertyAttestationsByRefAndSchema(rawProperties)\n\n await saveEasPropertiesToDb({\n itemProperties,\n itemSeeds,\n })\n\n await getRelatedSeedsAndVersions()\n scheduleBulkFilesDownloadFromEasSync(addresses)\n\n try {\n const itemMod = await import('../../Item/Item')\n await itemMod.Item.rehydrateCachedItemsFromDbAfterEasSync()\n } catch (err) {\n console.warn('[item/events] [syncDbWithEas] rehydrateCachedItemsFromDbAfterEasSync:', err)\n }\n eventEmitter.emit(EAS_SEED_DATA_SYNCED_TO_DB_EVENT)\n}\n\n"],"names":["BaseDb","modelsTable","modelUids","eq","toSnakeCase","seeds","inArray","generateId","escapeSqliteString","versions","sql","parseEasPropertyMetadata","camelCase","metadata","and","getPropertyIdForModelAndName","setSchemaUidForSchemaDefinition","parseEasRelationPropertyName","startCase","modelPropertiesToObject","BaseQueryClient","BaseEasClient","GET_SEEDS","GET_VERSIONS","GET_PROPERTIES","pickLatestPropertyAttestationsByRefAndSchema","getAllAddressesFromDb","getModelSchemasFromEas","getSeedsFromSchemaUids","getItemVersionsFromEas","getItemPropertiesFromEas","scheduleBulkFilesDownloadFromEasSync","eventEmitter","EAS_SEED_DATA_SYNCED_TO_DB_EVENT"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAcA,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAuB;AASzD,MAAM,eAAe,GAAoB,YAAW;;AAEzD,IAAA,MAAM,QAAQ,GAAG,MAAM,oDAAO,qBAAmB,8CAAC;AAClD,IAAA,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ;AAC1B,IAAA,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;IACnC,MAAM,YAAY,GAAkB,EAAE;AAEtC,IAAA,MAAM,KAAK,GAAGA,eAAM,CAAC,QAAQ,EAAE;AAE/B,IAAA,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE;AAC7B,QAAA,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS;AACjC,QAAA,IAAI,CAAC,SAAS;YAAE;QAChB,MAAM,eAAe,GAAG,MAAM;AAC3B,aAAA,MAAM,CAAC;YACN,EAAE,EAAEC,eAAW,CAAC,EAAE;YAClB,IAAI,EAAEA,eAAW,CAAC,IAAI;YACtB,GAAG,EAAEC,kBAAS,CAAC,GAAG;SACnB;aACA,IAAI,CAACD,eAAW;AAChB,aAAA,QAAQ,CAACC,kBAAS,EAAEC,aAAE,CAACF,eAAW,CAAC,EAAE,EAAEC,kBAAS,CAAC,OAAO,CAAC;aACzD,KAAK,CAACC,aAAE,CAACF,eAAW,CAAC,IAAI,EAAE,SAAS,CAAC;aACrC,KAAK,CAAC,CAAC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AA,CAAC;AAEF,IAAA,MAAM,aAAa,GAAG,MAAMC,8BAAwB,CAAC;QACnD,WAAW;AACX,QAAA,cAAc,EAAE,KAAK;AACtB,KAAA,CAAC;AACF,IAAA,MAAM,cAAc,GAAGL,kDAA4C,CAAC,aAAa,CAAC;AAElF,IAAA,MAAM,qBAAqB,CAAC;QAC1B,cAAc;QACd,SAAS;AACV,KAAA,CAAC;IAEF,MAAM,0BAA0B,EAAE;IAClCM,6CAAoC,CAAC,SAAS,CAAC;AAE/C,IAAA,IAAI;AACF,QAAA,MAAM,OAAO,GAAG,MAAM,oDAAO,qBAAiB,6CAAC;AAC/C,QAAA,MAAM,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE;IAC7D;IAAE,OAAO,GAAG,EAAE;AACZ,QAAA,OAAO,CAAC,IAAI,CAAC,uEAAuE,EAAE,GAAG,CAAC;IAC5F;AACA,IAAAC,qBAAY,CAAC,IAAI,CAACC,yCAAgC,CAAC;AACrD;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as BasePathResolver,
|
|
2
|
-
import './constants-
|
|
1
|
+
import { t as BasePathResolver, B as BaseFileManager, a as BaseDb } from './BasePathResolver-DWY_hb8w.js';
|
|
2
|
+
import './constants-B7aNfB_1.js';
|
|
3
3
|
import { BaseEasClient, BaseQueryClient } from '@seedprotocol/eas';
|
|
4
4
|
import { BaseArweaveClient } from '@seedprotocol/arweave';
|
|
5
5
|
import 'drizzle-orm/sqlite-core';
|
|
@@ -10,6 +10,7 @@ import 'pluralize';
|
|
|
10
10
|
import '@sinclair/typebox';
|
|
11
11
|
import 'nanoid';
|
|
12
12
|
import 'nanoid-dictionary';
|
|
13
|
+
import '@seedprotocol/query';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Wire all platform facades to the given service instances.
|
|
@@ -24,4 +25,4 @@ function configurePlatform(services) {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export { configurePlatform };
|
|
27
|
-
//# sourceMappingURL=configurePlatform-
|
|
28
|
+
//# sourceMappingURL=configurePlatform-CXQCT7N8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurePlatform-
|
|
1
|
+
{"version":3,"file":"configurePlatform-CXQCT7N8.js","sources":["../../src/platform/configurePlatform.ts"],"sourcesContent":["import { BasePathResolver } from '@/helpers/PathResolver/BasePathResolver'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { BaseArweaveClient } from '@/helpers'\nimport { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'\nimport { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'\nimport type { PlatformServices } from './types'\n\n/**\n * Wire all platform facades to the given service instances.\n */\nexport function configurePlatform(services: PlatformServices): void {\n BasePathResolver.configure(services.pathResolver)\n BaseFileManager.configure(services.fileManager)\n BaseDb.configure(services.db)\n BaseArweaveClient.configure(services.arweaveClient)\n BaseEasClient.configure(services.easClient)\n BaseQueryClient.configure(services.queryClient)\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAQA;;AAEG;AACG,SAAU,iBAAiB,CAAC,QAA0B,EAAA;AAC1D,IAAA,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC;AACjD,IAAA,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC;AAC/C,IAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC7B,IAAA,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC;AACnD,IAAA,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC;AAC3C,IAAA,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC;AACjD;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
|
-
import {
|
|
3
|
-
import { BaseArweaveClient } from '@seedprotocol/arweave';
|
|
2
|
+
import { a as BaseDb, b as metadata, B as BaseFileManager } from './BasePathResolver-DWY_hb8w.js';
|
|
3
|
+
import { isEasAttestationExplorerUrl, BaseArweaveClient } from '@seedprotocol/arweave';
|
|
4
4
|
import '@seedprotocol/eas';
|
|
5
5
|
import 'xstate';
|
|
6
6
|
import 'pluralize';
|
|
@@ -8,6 +8,7 @@ import { Type } from '@sinclair/typebox';
|
|
|
8
8
|
import { and, eq } from 'drizzle-orm';
|
|
9
9
|
import 'nanoid';
|
|
10
10
|
import 'nanoid-dictionary';
|
|
11
|
+
import '@seedprotocol/query';
|
|
11
12
|
|
|
12
13
|
/** Default maximum length for Text properties when not explicitly set. Html holds arbitrary-length content and does not use this limit. */
|
|
13
14
|
const DEFAULT_TEXT_MAX_LENGTH = 255;
|
|
@@ -296,6 +297,9 @@ function classifyMediaRef(raw, options) {
|
|
|
296
297
|
return { kind: 'unknown', raw: s };
|
|
297
298
|
}
|
|
298
299
|
if (s.startsWith('http://') || s.startsWith('https://') || s.startsWith('blob:') || s.startsWith('data:')) {
|
|
300
|
+
if (isEasAttestationExplorerUrl(s)) {
|
|
301
|
+
return { kind: 'nonMediaUrl', href: s };
|
|
302
|
+
}
|
|
299
303
|
return { kind: 'url', href: s };
|
|
300
304
|
}
|
|
301
305
|
const unwrapped = unwrapRelationString(s);
|
|
@@ -371,6 +375,12 @@ async function resolveMediaRef(raw, options) {
|
|
|
371
375
|
href: classification.href,
|
|
372
376
|
source: 'direct',
|
|
373
377
|
};
|
|
378
|
+
case 'nonMediaUrl':
|
|
379
|
+
return {
|
|
380
|
+
status: 'unresolved',
|
|
381
|
+
reason: 'non_media_url',
|
|
382
|
+
classification,
|
|
383
|
+
};
|
|
374
384
|
case 'seedLocalId':
|
|
375
385
|
return {
|
|
376
386
|
status: 'unresolved',
|
|
@@ -557,21 +567,6 @@ const convertTxIdToImage = async (txId) => {
|
|
|
557
567
|
const getArweaveUrlForTransaction = (storageTransactionId) => {
|
|
558
568
|
return BaseArweaveClient.getRawUrl(storageTransactionId);
|
|
559
569
|
};
|
|
560
|
-
const parseEasRelationPropertyName = (easPropertyName) => {
|
|
561
|
-
// Split the input string on the first underscore
|
|
562
|
-
const [singularProperty, modelName, idSegment] = easPropertyName.split('_');
|
|
563
|
-
// If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)
|
|
564
|
-
const isList = idSegment === 'ids';
|
|
565
|
-
// Create the final property name by pluralizing the singular part
|
|
566
|
-
const propertyName = singularProperty.endsWith('s')
|
|
567
|
-
? singularProperty
|
|
568
|
-
: singularProperty + 's';
|
|
569
|
-
return {
|
|
570
|
-
propertyName, // Plural form of the property name
|
|
571
|
-
modelName, // Model name extracted from the second part
|
|
572
|
-
isList, // True if the property is a list (e.g., 'ids' is present)
|
|
573
|
-
};
|
|
574
|
-
};
|
|
575
570
|
|
|
576
571
|
const ENV = (typeof process !== 'undefined' && process.env)
|
|
577
572
|
? process.env
|
|
@@ -656,5 +651,5 @@ const EAS_ENDPOINT = ENV.NEXT_PUBLIC_EAS_ENDPOINT ||
|
|
|
656
651
|
*/
|
|
657
652
|
ENV.NEXT_PUBLIC_ARWEAVE_HOST || 'ar.seedprotocol.io';
|
|
658
653
|
|
|
659
|
-
export {
|
|
660
|
-
//# sourceMappingURL=constants-
|
|
654
|
+
export { Boolean as B, ClientManagerState as C, DEFAULT_TEXT_MAX_LENGTH as D, EAS_ENDPOINT as E, File as F, Html as H, Image as I, Json as J, List as L, ModelPropertyDataTypes as M, Number as N, Property as P, Relation as R, THtmlEmbeddedDataUriPolicy as T, Date$1 as a, PropertyConstructor as b, PropertyMetadataKey as c, TProperty as d, TPropertyConstructor as e, TPropertyDataType as f, TPropertyDefs as g, TStorageType as h, TValidationRules as i, Text as j, normalizeRelationPropertyValue as k, getCorrectId as l, getArweaveUrlForTransaction as m, normalizeDataType as n, MachineIds as o, classifyMediaRef as p, getFeedItemStringField as q, resolveSeedIdsFromRefString as r, normalizeFeedItemFields as s, toSnakeCase as t, resolveMediaRef as u, getStorageTransactionIdForSeedUid as v, convertTxIdToImage as w, getDataTypeFromString as x, getMimeType as y, ClientManagerEvents as z };
|
|
655
|
+
//# sourceMappingURL=constants-B7aNfB_1.js.map
|