@seedprotocol/sdk 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ArweaveClient-DLKAaS3K.js → ArweaveClient-BdQaTOZ4.js} +3 -3
- package/dist/ArweaveClient-BdQaTOZ4.js.map +1 -0
- package/dist/{ArweaveClient-Caio37h1.js → ArweaveClient-nrTU_rhU.js} +3 -3
- package/dist/ArweaveClient-nrTU_rhU.js.map +1 -0
- package/dist/{Db-DJAG-5Di.js → Db-CWKaeNQH.js} +3 -102
- package/dist/Db-CWKaeNQH.js.map +1 -0
- package/dist/{Db-C9fppVRl.js → Db-Cq4q88X_.js} +21 -5
- package/dist/Db-Cq4q88X_.js.map +1 -0
- package/dist/{EasClient-DQGAIj-b.js → EasClient-Du9_TULE.js} +2 -2
- package/dist/EasClient-Du9_TULE.js.map +1 -0
- package/dist/{EasClient-T7Nx9185.js → EasClient-ZCIE6UQq.js} +2 -2
- package/dist/EasClient-ZCIE6UQq.js.map +1 -0
- package/dist/{FileManager-BohtoKYo.js → FileManager-Cub9icdd.js} +2 -2
- package/dist/FileManager-Cub9icdd.js.map +1 -0
- package/dist/{FileManager-d64CkqXy.js → FileManager-HSFEess-.js} +2 -2
- package/dist/FileManager-HSFEess-.js.map +1 -0
- package/dist/Item/Item.d.ts +2 -0
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
- package/dist/Item/service/itemMachineSingle.d.ts.map +1 -1
- package/dist/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
- package/dist/Model/Model.d.ts +5 -0
- package/dist/Model/Model.d.ts.map +1 -1
- package/dist/{ModelProperty-Cpd9xiIM.js → ModelProperty-D4zaeIOT.js} +22 -22
- package/dist/ModelProperty-D4zaeIOT.js.map +1 -0
- package/dist/{PathResolver-D6M0rzKV.js → PathResolver-DVLBs_qi.js} +2 -2
- package/dist/PathResolver-DVLBs_qi.js.map +1 -0
- package/dist/{PathResolver-CLZUWoX2.js → PathResolver-T1yEDECb.js} +2 -2
- package/dist/PathResolver-T1yEDECb.js.map +1 -0
- package/dist/{QueryClient-COQ_Rs4-.js → QueryClient-DcKDQuwz.js} +2 -2
- package/dist/QueryClient-DcKDQuwz.js.map +1 -0
- package/dist/{QueryClient-BUoz2Vb0.js → QueryClient-Vs9KN5kS.js} +2 -2
- package/dist/QueryClient-Vs9KN5kS.js.map +1 -0
- package/dist/{Schema-BZKBy5Tx.js → Schema-SbwqmoMM.js} +36 -36
- package/dist/Schema-SbwqmoMM.js.map +1 -0
- package/dist/{SchemaValidationService-F8No7BHp.js → SchemaValidationService-DHGIw4Nx.js} +2 -2
- package/dist/SchemaValidationService-DHGIw4Nx.js.map +1 -0
- package/dist/browser/db/drizzleFiles.d.ts +3 -2
- package/dist/browser/db/drizzleFiles.d.ts.map +1 -1
- package/dist/browser/react/item.d.ts +2 -0
- package/dist/browser/react/item.d.ts.map +1 -1
- package/dist/cjs/{ModelProperty-B4pV91tc.js → ModelProperty-DpjD0o0E.js} +16 -16
- package/dist/cjs/{ModelProperty-B4pV91tc.js.map → ModelProperty-DpjD0o0E.js.map} +1 -1
- package/dist/cjs/{Schema-TErl3J36.js → Schema-DkSBMBwz.js} +21 -21
- package/dist/cjs/{Schema-TErl3J36.js.map → Schema-DkSBMBwz.js.map} +1 -1
- package/dist/cjs/{SchemaValidationService-p5BbJV9T.js → SchemaValidationService-O3FCMROl.js} +2 -2
- package/dist/cjs/{SchemaValidationService-p5BbJV9T.js.map → SchemaValidationService-O3FCMROl.js.map} +1 -1
- package/dist/cjs/{getItem-BrnLfC12.js → getItem-BeAVMk54.js} +2 -2
- package/dist/cjs/{getItem-BrnLfC12.js.map → getItem-BeAVMk54.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-BcjCN_bD.js → getPublishPayload-CoLriAMV.js} +5 -5
- package/dist/cjs/{getPublishPayload-BcjCN_bD.js.map → getPublishPayload-CoLriAMV.js.map} +1 -1
- package/dist/cjs/{getPublishUploads-5_oXzwol.js → getPublishUploads-DDsT9zZ6.js} +3 -3
- package/dist/cjs/{getPublishUploads-5_oXzwol.js.map → getPublishUploads-DDsT9zZ6.js.map} +1 -1
- package/dist/cjs/{getSegmentedItemProperties-WFdizUDv.js → getSegmentedItemProperties-DGR0utR5.js} +2 -2
- package/dist/cjs/{getSegmentedItemProperties-WFdizUDv.js.map → getSegmentedItemProperties-DGR0utR5.js.map} +1 -1
- package/dist/cjs/{index-CXI4VF1H.js → index-B95Ng80C.js} +326 -180
- package/dist/cjs/index-B95Ng80C.js.map +1 -0
- package/dist/cjs/{index-BrmvhXsG.js → index-CvcOtzbi.js} +2 -2
- package/dist/cjs/index-CvcOtzbi.js.map +1 -0
- package/dist/cjs/ownership-Dm5ER1nI.js +103 -0
- package/dist/cjs/ownership-Dm5ER1nI.js.map +1 -0
- package/dist/client/ClientManager.d.ts +54 -43
- package/dist/client/ClientManager.d.ts.map +1 -1
- package/dist/client/actors/platformClassesInit.d.ts.map +1 -1
- package/dist/client/actors/saveConfig.d.ts.map +1 -1
- package/dist/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/db/drizzle/drizzle/0004_add_publisher_to_seeds.sql +1 -0
- package/dist/db/drizzle/drizzle/meta/0004_snapshot.json +857 -0
- package/dist/db/drizzle/drizzle/meta/_journal.json +7 -0
- package/dist/db/read/getItemData.d.ts.map +1 -1
- package/dist/db/read/getItems.d.ts +2 -0
- package/dist/db/read/getItems.d.ts.map +1 -1
- package/dist/db/write/createNewItem.d.ts.map +1 -1
- package/dist/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/{getItem-DaQVdeae.js → getItem-CqrJt-Ee.js} +2 -2
- package/dist/getItem-CqrJt-Ee.js.map +1 -0
- package/dist/{getPublishPayload-CWiLI1yd.js → getPublishPayload-BRgULCf3.js} +5 -5
- package/dist/getPublishPayload-BRgULCf3.js.map +1 -0
- package/dist/{getPublishUploads-DhvcKD_9.js → getPublishUploads-B0WArDfp.js} +3 -3
- package/dist/getPublishUploads-B0WArDfp.js.map +1 -0
- package/dist/{getSegmentedItemProperties-Cp4kcWIF.js → getSegmentedItemProperties-DZL9Ymd4.js} +2 -2
- package/dist/getSegmentedItemProperties-DZL9Ymd4.js.map +1 -0
- package/dist/helpers/addresses.d.ts +12 -0
- package/dist/helpers/addresses.d.ts.map +1 -0
- package/dist/helpers/db.d.ts +11 -0
- package/dist/helpers/db.d.ts.map +1 -1
- package/dist/helpers/ownership.d.ts +16 -0
- package/dist/helpers/ownership.d.ts.map +1 -0
- package/dist/{index-DBy53qbb.js → index-BIPPEMVY.js} +2 -2
- package/dist/index-BIPPEMVY.js.map +1 -0
- package/dist/{index-LfXKx_PE.js → index-BnF3MRZ8.js} +3 -3
- package/dist/index-BnF3MRZ8.js.map +1 -0
- package/dist/{index-Dk73a7JE.js → index-zsq08F5p.js} +342 -98
- package/dist/index-zsq08F5p.js.map +1 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +18 -15
- package/dist/main.js.map +1 -1
- package/dist/node/db/Db.d.ts.map +1 -1
- package/dist/node.js +10 -10
- package/dist/node.js.map +1 -1
- package/dist/ownership-CSsweVap.js +85 -0
- package/dist/ownership-CSsweVap.js.map +1 -0
- package/dist/{property-1o2MvYTm.js → property-Cqh_o0zx.js} +5 -5
- package/dist/property-Cqh_o0zx.js.map +1 -0
- package/dist/{queries-DA4G0iEN.js → queries-DSBgjcJJ.js} +2 -2
- package/dist/queries-DSBgjcJJ.js.map +1 -0
- package/dist/seedSchema/ModelSchemaSchema.d.ts +1 -1
- package/dist/seedSchema/ModelSchemaSchema.ts +4 -4
- package/dist/seedSchema/ModelUidSchema.ts +1 -1
- package/dist/seedSchema/PropertyUidSchema.ts +1 -1
- package/dist/seedSchema/SeedSchema.d.ts +19 -0
- package/dist/seedSchema/SeedSchema.d.ts.map +1 -1
- package/dist/seedSchema/SeedSchema.ts +1 -0
- package/dist/seedSchema/index.d.ts +10 -10
- package/dist/seedSchema/index.d.ts.map +1 -1
- package/dist/seedSchema/index.ts +10 -10
- package/dist/types/index.d.ts +11 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/item.d.ts +1 -0
- package/dist/types/item.d.ts.map +1 -1
- package/dist/types/machines.d.ts +2 -0
- package/dist/types/machines.d.ts.map +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +2 -9
- package/dist/ArweaveClient-Caio37h1.js.map +0 -1
- package/dist/ArweaveClient-DLKAaS3K.js.map +0 -1
- package/dist/Db-C9fppVRl.js.map +0 -1
- package/dist/Db-DJAG-5Di.js.map +0 -1
- package/dist/EasClient-DQGAIj-b.js.map +0 -1
- package/dist/EasClient-T7Nx9185.js.map +0 -1
- package/dist/FileManager-BohtoKYo.js.map +0 -1
- package/dist/FileManager-d64CkqXy.js.map +0 -1
- package/dist/ModelProperty-Cpd9xiIM.js.map +0 -1
- package/dist/PathResolver-CLZUWoX2.js.map +0 -1
- package/dist/PathResolver-D6M0rzKV.js.map +0 -1
- package/dist/QueryClient-BUoz2Vb0.js.map +0 -1
- package/dist/QueryClient-COQ_Rs4-.js.map +0 -1
- package/dist/Schema-BZKBy5Tx.js.map +0 -1
- package/dist/SchemaValidationService-F8No7BHp.js.map +0 -1
- package/dist/cjs/index-BrmvhXsG.js.map +0 -1
- package/dist/cjs/index-CXI4VF1H.js.map +0 -1
- package/dist/getItem-DaQVdeae.js.map +0 -1
- package/dist/getPublishPayload-CWiLI1yd.js.map +0 -1
- package/dist/getPublishUploads-DhvcKD_9.js.map +0 -1
- package/dist/getSegmentedItemProperties-Cp4kcWIF.js.map +0 -1
- package/dist/index-DBy53qbb.js.map +0 -1
- package/dist/index-Dk73a7JE.js.map +0 -1
- package/dist/index-LfXKx_PE.js.map +0 -1
- package/dist/property-1o2MvYTm.js.map +0 -1
- package/dist/queries-DA4G0iEN.js.map +0 -1
|
@@ -647,7 +647,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
647
647
|
return;
|
|
648
648
|
}
|
|
649
649
|
try {
|
|
650
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
650
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DpjD0o0E.js'); });
|
|
651
651
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
652
652
|
if (!ModelProperty) {
|
|
653
653
|
logger$x('createPropertyInstances: ModelProperty not available from dynamic import');
|
|
@@ -836,7 +836,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
836
836
|
// Step 2: Fallback to Schema context (only if database doesn't have the model)
|
|
837
837
|
// This handles the case where model exists in schema file but not yet in database
|
|
838
838
|
try {
|
|
839
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
839
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DkSBMBwz.js'); }).then(function (n) { return n.Schema$1; });
|
|
840
840
|
const { Schema } = schemaMod;
|
|
841
841
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
842
842
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
@@ -1080,7 +1080,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
1080
1080
|
}
|
|
1081
1081
|
// Mark schema as draft when a new model is created so saveNewVersion() can persist it
|
|
1082
1082
|
try {
|
|
1083
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1083
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DkSBMBwz.js'); }).then(function (n) { return n.Schema$1; });
|
|
1084
1084
|
const { Schema } = schemaMod;
|
|
1085
1085
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
1086
1086
|
schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
|
|
@@ -1124,10 +1124,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
1124
1124
|
const _validateModel = async () => {
|
|
1125
1125
|
try {
|
|
1126
1126
|
// Use dynamic imports to break circular dependencies
|
|
1127
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1127
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-O3FCMROl.js'); });
|
|
1128
1128
|
const { SchemaValidationService } = validationServiceMod;
|
|
1129
1129
|
const validationService = new SchemaValidationService();
|
|
1130
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1130
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DkSBMBwz.js'); }).then(function (n) { return n.Schema$1; });
|
|
1131
1131
|
const { Schema } = schemaMod;
|
|
1132
1132
|
// Validate model structure
|
|
1133
1133
|
const structureResult = validationService.validateModelStructure(context);
|
|
@@ -1239,7 +1239,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
1239
1239
|
return;
|
|
1240
1240
|
}
|
|
1241
1241
|
logger$v(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
|
|
1242
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
1242
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DpjD0o0E.js'); });
|
|
1243
1243
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1244
1244
|
if (!ModelProperty) {
|
|
1245
1245
|
logger$v('ModelProperty not available from dynamic import');
|
|
@@ -1344,7 +1344,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1344
1344
|
logger$u(structureMsg);
|
|
1345
1345
|
console.log(structureMsg); // Always log to console
|
|
1346
1346
|
// Use existing Model validation
|
|
1347
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1347
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-O3FCMROl.js'); });
|
|
1348
1348
|
const { SchemaValidationService } = validationServiceMod;
|
|
1349
1349
|
const validationService = new SchemaValidationService();
|
|
1350
1350
|
// Validate model structure
|
|
@@ -1363,7 +1363,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1363
1363
|
if (entityInput.entityData.schemaName) {
|
|
1364
1364
|
try {
|
|
1365
1365
|
logger$u(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
|
|
1366
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1366
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DkSBMBwz.js'); }).then(function (n) { return n.Schema$1; });
|
|
1367
1367
|
const { Schema } = schemaMod;
|
|
1368
1368
|
const schema = Schema.create(entityInput.entityData.schemaName, {
|
|
1369
1369
|
waitForReady: false,
|
|
@@ -1399,7 +1399,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1399
1399
|
}
|
|
1400
1400
|
else if (entityInput.entityType === 'modelProperty') {
|
|
1401
1401
|
// Use existing ModelProperty validation
|
|
1402
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1402
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-O3FCMROl.js'); });
|
|
1403
1403
|
const { SchemaValidationService } = validationServiceMod;
|
|
1404
1404
|
const validationService = new SchemaValidationService();
|
|
1405
1405
|
// Validate property structure
|
|
@@ -1414,7 +1414,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1414
1414
|
// If schema name and model name provided, validate against schema
|
|
1415
1415
|
if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
|
|
1416
1416
|
try {
|
|
1417
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
1417
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-DkSBMBwz.js'); }).then(function (n) { return n.Schema$1; });
|
|
1418
1418
|
const { Schema } = schemaMod;
|
|
1419
1419
|
const schema = Schema.create(entityInput.entityData._schemaName, {
|
|
1420
1420
|
waitForReady: false,
|
|
@@ -1443,7 +1443,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
1443
1443
|
}
|
|
1444
1444
|
else if (entityInput.entityType === 'schema') {
|
|
1445
1445
|
// Schema validation - use existing validation
|
|
1446
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
1446
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-O3FCMROl.js'); });
|
|
1447
1447
|
const { SchemaValidationService } = validationServiceMod;
|
|
1448
1448
|
const validationService = new SchemaValidationService();
|
|
1449
1449
|
const schemaResult = validationService.validateSchema(entityInput.entityData);
|
|
@@ -1480,6 +1480,7 @@ const seeds = sqliteCore.sqliteTable('seeds', {
|
|
|
1480
1480
|
uid: sqliteCore.text('uid'),
|
|
1481
1481
|
schemaUid: sqliteCore.text('schema_uid'),
|
|
1482
1482
|
type: sqliteCore.text('type'),
|
|
1483
|
+
publisher: sqliteCore.text('publisher'),
|
|
1483
1484
|
attestationRaw: sqliteCore.text('attestation_raw'),
|
|
1484
1485
|
attestationCreatedAt: sqliteCore.int('attestation_created_at'),
|
|
1485
1486
|
createdAt: sqliteCore.int('created_at'),
|
|
@@ -1993,7 +1994,7 @@ async function checkIfPropertyIsEdited(modelName, propertyName, schemaFileValue)
|
|
|
1993
1994
|
const cacheKey = `${modelName}:${propertyName}`;
|
|
1994
1995
|
// First, check the in-memory cache (for current session edits)
|
|
1995
1996
|
// Robust dynamic import for consumer re-bundling (named or default export)
|
|
1996
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
1997
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DpjD0o0E.js'); });
|
|
1997
1998
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1998
1999
|
if (!ModelProperty) {
|
|
1999
2000
|
logger$t('ModelProperty not available from dynamic import');
|
|
@@ -2673,13 +2674,49 @@ const savePropertyToDb = async (property) => {
|
|
|
2673
2674
|
logger$t(`Created property ${property.modelName}:${property.name} in database`);
|
|
2674
2675
|
}
|
|
2675
2676
|
};
|
|
2676
|
-
|
|
2677
|
+
function parseAddressConfig(value) {
|
|
2678
|
+
if (!value)
|
|
2679
|
+
return null;
|
|
2680
|
+
try {
|
|
2681
|
+
const parsed = JSON.parse(value);
|
|
2682
|
+
if (Array.isArray(parsed)) {
|
|
2683
|
+
return { owned: parsed, watched: [] };
|
|
2684
|
+
}
|
|
2685
|
+
if (parsed && typeof parsed === 'object' && Array.isArray(parsed.owned)) {
|
|
2686
|
+
return {
|
|
2687
|
+
owned: parsed.owned,
|
|
2688
|
+
watched: Array.isArray(parsed.watched) ? parsed.watched : [],
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
return null;
|
|
2692
|
+
}
|
|
2693
|
+
catch {
|
|
2694
|
+
return null;
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
const getOwnedAddressesFromDb = async () => {
|
|
2698
|
+
const config = await getAddressConfigFromDb();
|
|
2699
|
+
return config?.owned ?? [];
|
|
2700
|
+
};
|
|
2701
|
+
const getWatchedAddressesFromDb = async () => {
|
|
2702
|
+
const config = await getAddressConfigFromDb();
|
|
2703
|
+
return config?.watched ?? [];
|
|
2704
|
+
};
|
|
2705
|
+
/**
|
|
2706
|
+
* Returns owned + watched addresses. Use for EAS sync and file download.
|
|
2707
|
+
*/
|
|
2708
|
+
const getAllAddressesFromDb = async () => {
|
|
2709
|
+
const config = await getAddressConfigFromDb();
|
|
2710
|
+
if (!config)
|
|
2711
|
+
return [];
|
|
2712
|
+
return [...config.owned, ...config.watched];
|
|
2713
|
+
};
|
|
2714
|
+
async function getAddressConfigFromDb() {
|
|
2677
2715
|
const appDb = BaseDb.getAppDb();
|
|
2678
2716
|
if (!appDb) {
|
|
2679
2717
|
return new Promise((resolve) => {
|
|
2680
2718
|
setTimeout(async () => {
|
|
2681
|
-
|
|
2682
|
-
resolve(addresses);
|
|
2719
|
+
resolve(await getAddressConfigFromDb());
|
|
2683
2720
|
}, 500);
|
|
2684
2721
|
});
|
|
2685
2722
|
}
|
|
@@ -2689,14 +2726,25 @@ const getAddressesFromDb = async () => {
|
|
|
2689
2726
|
.where(drizzleOrm.eq(appState.key, 'addresses'))
|
|
2690
2727
|
.limit(1);
|
|
2691
2728
|
if (!appStatesRecords || appStatesRecords.length === 0) {
|
|
2692
|
-
|
|
2729
|
+
return null;
|
|
2693
2730
|
}
|
|
2694
|
-
const
|
|
2695
|
-
|
|
2696
|
-
|
|
2731
|
+
const addressArrayString = appStatesRecords[0].value;
|
|
2732
|
+
return parseAddressConfig(addressArrayString);
|
|
2733
|
+
}
|
|
2734
|
+
const getAddressesFromDb = async () => {
|
|
2735
|
+
const config = await getAddressConfigFromDb();
|
|
2736
|
+
if (!config || config.owned.length === 0) {
|
|
2697
2737
|
throw new Error('No addresses found');
|
|
2698
2738
|
}
|
|
2699
|
-
return
|
|
2739
|
+
return config.owned;
|
|
2740
|
+
};
|
|
2741
|
+
/**
|
|
2742
|
+
* Like getAddressesFromDb but returns [] instead of throwing when no addresses are configured.
|
|
2743
|
+
* Returns owned addresses. Use getAllAddressesFromDb for sync (owned + watched).
|
|
2744
|
+
*/
|
|
2745
|
+
const getAddressesFromDbOptional = async () => {
|
|
2746
|
+
const config = await getAddressConfigFromDb();
|
|
2747
|
+
return config?.owned ?? [];
|
|
2700
2748
|
};
|
|
2701
2749
|
/**
|
|
2702
2750
|
* Write model to database and create model_schemas join entry
|
|
@@ -3158,14 +3206,18 @@ var db = /*#__PURE__*/Object.freeze({
|
|
|
3158
3206
|
createOrUpdate: createOrUpdate,
|
|
3159
3207
|
escapeSqliteString: escapeSqliteString,
|
|
3160
3208
|
getAddressesFromDb: getAddressesFromDb,
|
|
3209
|
+
getAddressesFromDbOptional: getAddressesFromDbOptional,
|
|
3210
|
+
getAllAddressesFromDb: getAllAddressesFromDb,
|
|
3161
3211
|
getModelId: getModelId,
|
|
3162
3212
|
getModelIdByFileId: getModelIdByFileId,
|
|
3163
3213
|
getModelNameByModelId: getModelNameByModelId,
|
|
3164
3214
|
getObjectForRow: getObjectForRow,
|
|
3215
|
+
getOwnedAddressesFromDb: getOwnedAddressesFromDb,
|
|
3165
3216
|
getPropertyModelNameAndDataType: getPropertyModelNameAndDataType,
|
|
3166
3217
|
getSchemaId: getSchemaId,
|
|
3167
3218
|
getSchemaIdByFileId: getSchemaIdByFileId,
|
|
3168
3219
|
getSqlResultObject: getSqlResultObject,
|
|
3220
|
+
getWatchedAddressesFromDb: getWatchedAddressesFromDb,
|
|
3169
3221
|
loadModelsFromDbForSchema: loadModelsFromDbForSchema,
|
|
3170
3222
|
renameModelInDb: renameModelInDb,
|
|
3171
3223
|
savePropertyToDb: savePropertyToDb,
|
|
@@ -3219,7 +3271,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
3219
3271
|
// initial write completes is not overwritten by the stale requestWrite payload.
|
|
3220
3272
|
let dataToWrite = input.entityData;
|
|
3221
3273
|
try {
|
|
3222
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
3274
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-DpjD0o0E.js'); });
|
|
3223
3275
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
3224
3276
|
if (ModelProperty && typeof ModelProperty.getById === 'function') {
|
|
3225
3277
|
const instance = ModelProperty.getById(input.entityId);
|
|
@@ -3610,7 +3662,7 @@ const modelMachine = xstate.setup({
|
|
|
3610
3662
|
// Create ModelProperty instances for any new property IDs
|
|
3611
3663
|
if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
|
|
3612
3664
|
// Import and create instances asynchronously (fire-and-forget)
|
|
3613
|
-
Promise.resolve().then(function () { return require('./ModelProperty-
|
|
3665
|
+
Promise.resolve().then(function () { return require('./ModelProperty-DpjD0o0E.js'); }).then(({ ModelProperty }) => {
|
|
3614
3666
|
const createPromises = newPropertyIds.map(async (propertyFileId) => {
|
|
3615
3667
|
try {
|
|
3616
3668
|
const property = await ModelProperty.createById(propertyFileId);
|
|
@@ -4576,13 +4628,15 @@ var versionData = /*#__PURE__*/Object.freeze({
|
|
|
4576
4628
|
|
|
4577
4629
|
const logger$p = debug('seedSdk:item:actors:loadOrCreateItem');
|
|
4578
4630
|
/**
|
|
4579
|
-
* Create ItemProperty instances for all metadata records to ensure they're cached
|
|
4631
|
+
* Create ItemProperty instances for all metadata records to ensure they're cached.
|
|
4632
|
+
* Passes propertyRecordSchema from Model when available (Fix 3: enables value persistence for runtime-created models).
|
|
4580
4633
|
* @param metadataRows - Array of metadata records to create ItemProperty instances for
|
|
4581
4634
|
* @param seedLocalId - Seed local ID
|
|
4582
4635
|
* @param seedUid - Seed UID
|
|
4636
|
+
* @param modelName - Model name for resolving propertyRecordSchema from Model
|
|
4583
4637
|
* @returns Map of propertyName -> ItemProperty instance
|
|
4584
4638
|
*/
|
|
4585
|
-
const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid) => {
|
|
4639
|
+
const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, modelName) => {
|
|
4586
4640
|
const propertyInstances = new Map();
|
|
4587
4641
|
if (metadataRows.length === 0) {
|
|
4588
4642
|
return propertyInstances;
|
|
@@ -4590,20 +4644,40 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid) =
|
|
|
4590
4644
|
try {
|
|
4591
4645
|
const itemPropertyMod = await Promise.resolve().then(function () { return ItemProperty$1; });
|
|
4592
4646
|
const { ItemProperty } = itemPropertyMod;
|
|
4593
|
-
|
|
4647
|
+
const { modelPropertiesToObject } = await Promise.resolve().then(function () { return model; });
|
|
4648
|
+
const { Model } = await Promise.resolve().then(function () { return Model$1; });
|
|
4649
|
+
// Resolve Model and build property schemas for propertyRecordSchema (Fix 3)
|
|
4650
|
+
let propertySchemas = {};
|
|
4651
|
+
const model$1 = Model.getByName(modelName);
|
|
4652
|
+
if (model$1?.properties?.length) {
|
|
4653
|
+
propertySchemas = modelPropertiesToObject(model$1.properties);
|
|
4654
|
+
}
|
|
4655
|
+
// Create instances for all metadata records in parallel with propertyRecordSchema
|
|
4594
4656
|
const createPromises = metadataRows.map(async (metaRow) => {
|
|
4595
4657
|
try {
|
|
4596
|
-
const
|
|
4597
|
-
|
|
4658
|
+
const propertyName = metaRow.propertyName;
|
|
4659
|
+
if (!propertyName) {
|
|
4660
|
+
logger$p(`Metadata row missing propertyName, skipping`);
|
|
4661
|
+
return;
|
|
4662
|
+
}
|
|
4663
|
+
const createProps = {
|
|
4664
|
+
propertyName,
|
|
4598
4665
|
seedLocalId,
|
|
4599
4666
|
seedUid,
|
|
4600
|
-
|
|
4667
|
+
modelName,
|
|
4668
|
+
propertyValue: metaRow.propertyValue ?? undefined,
|
|
4669
|
+
versionLocalId: metaRow.versionLocalId ?? undefined,
|
|
4670
|
+
versionUid: metaRow.versionUid ?? undefined,
|
|
4671
|
+
schemaUid: metaRow.schemaUid ?? undefined,
|
|
4672
|
+
propertyRecordSchema: propertySchemas[propertyName] ?? undefined,
|
|
4673
|
+
};
|
|
4674
|
+
const property = ItemProperty.create(createProps, { waitForReady: false });
|
|
4601
4675
|
if (property) {
|
|
4602
|
-
propertyInstances.set(
|
|
4603
|
-
logger$p(`Created/cached ItemProperty instance for propertyName "${
|
|
4676
|
+
propertyInstances.set(propertyName, property);
|
|
4677
|
+
logger$p(`Created/cached ItemProperty instance for propertyName "${propertyName}" with propertyRecordSchema: ${!!createProps.propertyRecordSchema}`);
|
|
4604
4678
|
}
|
|
4605
4679
|
else {
|
|
4606
|
-
logger$p(`ItemProperty.
|
|
4680
|
+
logger$p(`ItemProperty.create returned undefined for propertyName "${propertyName}"`);
|
|
4607
4681
|
}
|
|
4608
4682
|
}
|
|
4609
4683
|
catch (error) {
|
|
@@ -4623,7 +4697,6 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid) =
|
|
|
4623
4697
|
const loadOrCreateItem = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
4624
4698
|
const _loadOrCreateItem = async () => {
|
|
4625
4699
|
const { seedLocalId, seedUid, modelName } = context;
|
|
4626
|
-
console.log(`[loadOrCreateItem] Called for modelName: ${modelName}, seedLocalId: ${seedLocalId}, seedUid: ${seedUid}`);
|
|
4627
4700
|
logger$p(`loadOrCreateItem called for modelName: ${modelName}, seedLocalId: ${seedLocalId}, seedUid: ${seedUid}`);
|
|
4628
4701
|
if (!seedLocalId && !seedUid) {
|
|
4629
4702
|
throw new Error('seedLocalId or seedUid is required');
|
|
@@ -4735,16 +4808,11 @@ const loadOrCreateItem = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
4735
4808
|
.from(metadata$1)
|
|
4736
4809
|
.where(drizzleOrm.and(drizzleOrm.eq(metadata$1.seedLocalId, resolvedSeedLocalId), drizzleOrm.eq(metadata$1.versionLocalId, latestVersionLocalId)));
|
|
4737
4810
|
logger$p(`Found ${metadataRecords.length} metadata records for version ${latestVersionLocalId}`);
|
|
4738
|
-
console.log(`[loadOrCreateItem] Found ${metadataRecords.length} metadata records for version ${latestVersionLocalId}`);
|
|
4739
|
-
if (metadataRecords.length > 0) {
|
|
4740
|
-
console.log(`[loadOrCreateItem] Metadata property names:`, metadataRecords.map((r) => r.propertyName));
|
|
4741
|
-
}
|
|
4742
4811
|
// Step 4: Create ItemProperty instances from metadata records
|
|
4743
4812
|
// This ensures they're in the cache when Item.properties getter is called
|
|
4744
4813
|
const propertyInstances = metadataRecords.length > 0
|
|
4745
|
-
? await createItemPropertyInstances(metadataRecords, resolvedSeedLocalId, resolvedSeedUid)
|
|
4814
|
+
? await createItemPropertyInstances(metadataRecords, resolvedSeedLocalId, resolvedSeedUid, modelName)
|
|
4746
4815
|
: new Map();
|
|
4747
|
-
console.log(`[loadOrCreateItem] Created ${propertyInstances.size} property instances:`, Array.from(propertyInstances.keys()));
|
|
4748
4816
|
// Step 5: Return loaded item data with property instances
|
|
4749
4817
|
sendBack({
|
|
4750
4818
|
type: 'loadOrCreateItemSuccess',
|
|
@@ -4789,9 +4857,9 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
4789
4857
|
sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
|
|
4790
4858
|
return;
|
|
4791
4859
|
}
|
|
4792
|
-
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-
|
|
4860
|
+
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DDsT9zZ6.js'); });
|
|
4793
4861
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
4794
|
-
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-
|
|
4862
|
+
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-CoLriAMV.js'); });
|
|
4795
4863
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
4796
4864
|
await getPublishUploads(item);
|
|
4797
4865
|
// For first iteration: no Arweave sign/upload - pass empty uploadedTransactions.
|
|
@@ -4964,14 +5032,18 @@ const itemMachineSingle = xstate.setup({
|
|
|
4964
5032
|
actions: xstate.assign(({ context, event }) => {
|
|
4965
5033
|
const item = event.item;
|
|
4966
5034
|
const existingPropertyInstances = context.propertyInstances || new Map();
|
|
4967
|
-
|
|
4968
|
-
// Merge property instances from loadOrCreateItem
|
|
5035
|
+
// Merge property instances from loadOrCreateItem (Fix 2: preserve existing when it has propertyRecordSchema and incoming doesn't)
|
|
4969
5036
|
if (item.propertyInstances) {
|
|
4970
5037
|
for (const [propertyName, propertyInstance] of item.propertyInstances) {
|
|
5038
|
+
const existing = existingPropertyInstances.get(propertyName);
|
|
5039
|
+
const existingHasSchema = existing?.propertyDef;
|
|
5040
|
+
const incomingHasSchema = propertyInstance?.propertyDef;
|
|
5041
|
+
if (existingHasSchema && !incomingHasSchema) {
|
|
5042
|
+
continue; // Preserve existing instance with schema
|
|
5043
|
+
}
|
|
4971
5044
|
existingPropertyInstances.set(propertyName, propertyInstance);
|
|
4972
5045
|
}
|
|
4973
5046
|
}
|
|
4974
|
-
console.log(`[itemMachine] After merge, total propertyInstances:`, Array.from(existingPropertyInstances.keys()));
|
|
4975
5047
|
return {
|
|
4976
5048
|
...context,
|
|
4977
5049
|
seedLocalId: item.seedLocalId || context.seedLocalId,
|
|
@@ -5327,6 +5399,26 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
|
5327
5399
|
}
|
|
5328
5400
|
const seedRow = seedRows[0];
|
|
5329
5401
|
const resolvedSeedLocalId = seedRow.seedLocalId;
|
|
5402
|
+
// Fix 5: Derive schemaName for multi-schema Model resolution (models -> model_schemas -> schemas)
|
|
5403
|
+
let schemaName;
|
|
5404
|
+
const normalizedModelName = modelName ? lodashEs.startCase(modelName) : (seedRow.type ? lodashEs.startCase(seedRow.type) : undefined);
|
|
5405
|
+
if (appDb && normalizedModelName) {
|
|
5406
|
+
try {
|
|
5407
|
+
const schemaRows = await appDb
|
|
5408
|
+
.select({ schemaName: schemas.name })
|
|
5409
|
+
.from(models$1)
|
|
5410
|
+
.innerJoin(modelSchemas, drizzleOrm.eq(models$1.id, modelSchemas.modelId))
|
|
5411
|
+
.innerJoin(schemas, drizzleOrm.eq(modelSchemas.schemaId, schemas.id))
|
|
5412
|
+
.where(drizzleOrm.eq(models$1.name, normalizedModelName))
|
|
5413
|
+
.limit(1);
|
|
5414
|
+
if (schemaRows.length > 0 && schemaRows[0].schemaName) {
|
|
5415
|
+
schemaName = schemaRows[0].schemaName;
|
|
5416
|
+
}
|
|
5417
|
+
}
|
|
5418
|
+
catch (error) {
|
|
5419
|
+
logger$n('[getItemData] Error deriving schemaName:', error);
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5330
5422
|
// Now get version data if it exists - query versions table directly
|
|
5331
5423
|
let versionRow = {
|
|
5332
5424
|
versionsCount: 0,
|
|
@@ -5357,6 +5449,7 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
|
5357
5449
|
let itemData = {
|
|
5358
5450
|
...seedRow,
|
|
5359
5451
|
...versionRow,
|
|
5452
|
+
schemaName,
|
|
5360
5453
|
};
|
|
5361
5454
|
const propertiesData = await getItemProperties({
|
|
5362
5455
|
seedLocalId,
|
|
@@ -5380,12 +5473,28 @@ const getItemData = async ({ modelName, seedLocalId, seedUid, }) => {
|
|
|
5380
5473
|
return itemData;
|
|
5381
5474
|
};
|
|
5382
5475
|
|
|
5383
|
-
const getItemsData = async ({ modelName, deleted, }) => {
|
|
5476
|
+
const getItemsData = async ({ modelName, deleted, includeEas = false, addressFilter, }) => {
|
|
5384
5477
|
const appDb = BaseDb.getAppDb();
|
|
5385
5478
|
const conditions = [];
|
|
5479
|
+
if (!includeEas) {
|
|
5480
|
+
conditions.push(drizzleOrm.or(drizzleOrm.isNull(seeds.uid), drizzleOrm.eq(seeds.uid, '')));
|
|
5481
|
+
}
|
|
5386
5482
|
if (modelName) {
|
|
5387
5483
|
conditions.push(drizzleOrm.eq(seeds.type, casing.toSnakeCase(modelName)));
|
|
5388
5484
|
}
|
|
5485
|
+
if (addressFilter === 'owned') {
|
|
5486
|
+
const ownedAddresses = await getOwnedAddressesFromDb();
|
|
5487
|
+
if (ownedAddresses.length > 0) {
|
|
5488
|
+
conditions.push(drizzleOrm.or(drizzleOrm.inArray(seeds.publisher, ownedAddresses), drizzleOrm.isNull(seeds.publisher)));
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
else if (addressFilter === 'watched') {
|
|
5492
|
+
const watchedAddresses = await getWatchedAddressesFromDb();
|
|
5493
|
+
if (watchedAddresses.length === 0) {
|
|
5494
|
+
return [];
|
|
5495
|
+
}
|
|
5496
|
+
conditions.push(drizzleOrm.inArray(seeds.publisher, watchedAddresses));
|
|
5497
|
+
}
|
|
5389
5498
|
if (deleted) {
|
|
5390
5499
|
conditions.push(drizzleOrm.or(drizzleOrm.isNotNull(seeds._markedForDeletion), drizzleOrm.eq(seeds._markedForDeletion, 1)));
|
|
5391
5500
|
}
|
|
@@ -5852,7 +5961,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
5852
5961
|
const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
|
|
5853
5962
|
const _resolveRelatedValue = async () => {
|
|
5854
5963
|
// Use dynamic import to break circular dependency
|
|
5855
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
5964
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-CvcOtzbi.js'); });
|
|
5856
5965
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
5857
5966
|
if (!propertyValue || !isRelation || populatedFromDb) {
|
|
5858
5967
|
return;
|
|
@@ -6191,7 +6300,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
6191
6300
|
// to use dynamically imported ModelPropertyDataTypes
|
|
6192
6301
|
const _hydrateFromDb = async () => {
|
|
6193
6302
|
// Use dynamic import to break circular dependency
|
|
6194
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
6303
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-CvcOtzbi.js'); });
|
|
6195
6304
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
6196
6305
|
const appDb = BaseDb.getAppDb();
|
|
6197
6306
|
const whereClauses = [];
|
|
@@ -6422,8 +6531,8 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
6422
6531
|
const modelName = metadataRecord.modelType || context.modelName;
|
|
6423
6532
|
if (modelName) {
|
|
6424
6533
|
try {
|
|
6425
|
-
// Normalize to PascalCase
|
|
6426
|
-
const normalizedModelName = lodashEs.
|
|
6534
|
+
// Normalize snake_case to PascalCase: "test_post" -> "TestPost" (startCase gives "Test Post" which fails)
|
|
6535
|
+
const normalizedModelName = lodashEs.upperFirst(lodashEs.camelCase(modelName));
|
|
6427
6536
|
// Query properties table to get property schema
|
|
6428
6537
|
const modelRecords = await db
|
|
6429
6538
|
.select({ id: models$1.id })
|
|
@@ -6454,6 +6563,28 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
6454
6563
|
// Continue without propertyRecordSchema
|
|
6455
6564
|
}
|
|
6456
6565
|
}
|
|
6566
|
+
if (!propertyRecordSchema && modelName) {
|
|
6567
|
+
try {
|
|
6568
|
+
const { Model } = await Promise.resolve().then(function () { return Model$1; });
|
|
6569
|
+
const { modelPropertiesToObject } = await Promise.resolve().then(function () { return model; });
|
|
6570
|
+
const normalizedModelName = lodashEs.upperFirst(lodashEs.camelCase(modelName));
|
|
6571
|
+
// Try PascalCase first ("post" -> "Post"); then findByModelType for names with spaces ("new_model" -> "New model")
|
|
6572
|
+
let model$1 = Model.getByName(normalizedModelName);
|
|
6573
|
+
if (!model$1?.properties?.length) {
|
|
6574
|
+
model$1 = Model.findByModelType(casing.toSnakeCase(modelName));
|
|
6575
|
+
}
|
|
6576
|
+
if (model$1?.properties?.length) {
|
|
6577
|
+
const schemas = modelPropertiesToObject(model$1.properties);
|
|
6578
|
+
propertyRecordSchema = schemas[propertyName];
|
|
6579
|
+
if (propertyRecordSchema) {
|
|
6580
|
+
logger$k(`Fallback: loaded propertyRecordSchema from Model for propertyName "${propertyName}"`);
|
|
6581
|
+
}
|
|
6582
|
+
}
|
|
6583
|
+
}
|
|
6584
|
+
catch (error) {
|
|
6585
|
+
logger$k(`Fallback Model lookup failed for propertyName "${propertyName}": ${error}`);
|
|
6586
|
+
}
|
|
6587
|
+
}
|
|
6457
6588
|
// Return loaded property data
|
|
6458
6589
|
sendBack({
|
|
6459
6590
|
type: 'loadOrCreatePropertySuccess',
|
|
@@ -6665,7 +6796,7 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
|
|
|
6665
6796
|
}
|
|
6666
6797
|
const _analyzeInput = async () => {
|
|
6667
6798
|
// Use dynamic import to break circular dependency
|
|
6668
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
6799
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-CvcOtzbi.js'); });
|
|
6669
6800
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
6670
6801
|
let propertyName = propertyNameRaw;
|
|
6671
6802
|
if (!propertyName) {
|
|
@@ -7023,7 +7154,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
|
|
|
7023
7154
|
}
|
|
7024
7155
|
const _saveRelation = async () => {
|
|
7025
7156
|
// Use dynamic import to break circular dependency
|
|
7026
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
7157
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-CvcOtzbi.js'); });
|
|
7027
7158
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
7028
7159
|
if (!propertyNameRaw) {
|
|
7029
7160
|
throw new Error('propertyName is required');
|
|
@@ -7726,6 +7857,32 @@ Promise.resolve().then(function () { return Model$1; }).then(module => {
|
|
|
7726
7857
|
// Return a default module structure to maintain type consistency
|
|
7727
7858
|
return {};
|
|
7728
7859
|
});
|
|
7860
|
+
/**
|
|
7861
|
+
* Resolve propertyRecordSchema from in-memory Model (Fix 6: enables value persistence when useItemProperty path doesn't go through loadOrCreateItem).
|
|
7862
|
+
* Tries getByName(pascalCase) first; if that fails (e.g. "New model" vs "NewModel"), falls back to findByModelType(modelType).
|
|
7863
|
+
*/
|
|
7864
|
+
const resolvePropertyRecordSchemaFromModel = async (modelName, propertyName, modelType) => {
|
|
7865
|
+
if (!modelName && !modelType)
|
|
7866
|
+
return undefined;
|
|
7867
|
+
try {
|
|
7868
|
+
const { Model } = await Promise.resolve().then(function () { return Model$1; });
|
|
7869
|
+
const { modelPropertiesToObject } = await Promise.resolve().then(function () { return model; });
|
|
7870
|
+
let model$1 = modelName ? Model.getByName(modelName) : undefined;
|
|
7871
|
+
if (!model$1?.properties?.length && modelType) {
|
|
7872
|
+
model$1 = Model.findByModelType(modelType);
|
|
7873
|
+
}
|
|
7874
|
+
if (!model$1?.properties?.length)
|
|
7875
|
+
return undefined;
|
|
7876
|
+
const schemas = modelPropertiesToObject(model$1.properties);
|
|
7877
|
+
const schema = schemas[propertyName];
|
|
7878
|
+
return schema;
|
|
7879
|
+
}
|
|
7880
|
+
catch {
|
|
7881
|
+
return undefined;
|
|
7882
|
+
}
|
|
7883
|
+
};
|
|
7884
|
+
/** Convert modelType (snake_case from DB) to Model name (PascalCase). startCase adds spaces ("Test Post"); Model names are "TestPost". */
|
|
7885
|
+
const modelTypeToModelName = (modelType) => modelType ? lodashEs.upperFirst(lodashEs.camelCase(modelType)) : '';
|
|
7729
7886
|
const logger$i = debug('seedSdk:property:class');
|
|
7730
7887
|
// Define tracked properties for the Proxy
|
|
7731
7888
|
// These properties will be read from/written to the actor context
|
|
@@ -7822,7 +7979,7 @@ class ItemProperty {
|
|
|
7822
7979
|
return;
|
|
7823
7980
|
}
|
|
7824
7981
|
// Use dynamic import to break circular dependency
|
|
7825
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
7982
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-CvcOtzbi.js'); });
|
|
7826
7983
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
7827
7984
|
const { context } = snapshot;
|
|
7828
7985
|
const { propertyRecordSchema } = context;
|
|
@@ -8211,10 +8368,14 @@ class ItemProperty {
|
|
|
8211
8368
|
return undefined;
|
|
8212
8369
|
}
|
|
8213
8370
|
// Ensure modelName for constructor: metadata may have modelType only, or neither (e.g. when Item passes it)
|
|
8371
|
+
// Use modelTypeToModelName: modelType is snake_case ("test_post"); Model names are PascalCase ("TestPost")
|
|
8214
8372
|
const data = propertyData;
|
|
8215
8373
|
const modelName = data.modelName ??
|
|
8216
|
-
((data.modelType ?
|
|
8217
|
-
|
|
8374
|
+
((data.modelType ? modelTypeToModelName(data.modelType) : '') || modelNameOption || '');
|
|
8375
|
+
// Fix 6: resolve propertyRecordSchema from Model so value setter can persist (useItemProperty path)
|
|
8376
|
+
// Pass modelType for fallback: "New model" -> "new_model" can't be reversed to exact name; findByModelType handles it
|
|
8377
|
+
const propertyRecordSchema = await resolvePropertyRecordSchemaFromModel(modelName, propertyName, data.modelType);
|
|
8378
|
+
foundProperty = ItemProperty.create({ ...propertyData, modelName, propertyRecordSchema }, { waitForReady: false });
|
|
8218
8379
|
}
|
|
8219
8380
|
if (!foundProperty) {
|
|
8220
8381
|
return undefined;
|
|
@@ -8237,9 +8398,16 @@ class ItemProperty {
|
|
|
8237
8398
|
const propertiesData = await getItemProperties({ seedLocalId, seedUid });
|
|
8238
8399
|
const instances = [];
|
|
8239
8400
|
for (const data of propertiesData) {
|
|
8401
|
+
const d = data;
|
|
8402
|
+
const modelName = d.modelName ?? (d.modelType ? modelTypeToModelName(d.modelType) : '') ?? '';
|
|
8403
|
+
// Fix 6: resolve propertyRecordSchema from Model so value setter can persist
|
|
8404
|
+
const propertyRecordSchema = d.propertyName
|
|
8405
|
+
? await resolvePropertyRecordSchemaFromModel(modelName, d.propertyName, d.modelType)
|
|
8406
|
+
: undefined;
|
|
8240
8407
|
const createProps = {
|
|
8241
8408
|
...data,
|
|
8242
|
-
modelName
|
|
8409
|
+
modelName,
|
|
8410
|
+
propertyRecordSchema,
|
|
8243
8411
|
};
|
|
8244
8412
|
const instance = this.create(createProps, { waitForReady: false });
|
|
8245
8413
|
if (instance) {
|
|
@@ -8374,10 +8542,15 @@ class ItemProperty {
|
|
|
8374
8542
|
});
|
|
8375
8543
|
}
|
|
8376
8544
|
async save() {
|
|
8545
|
+
const ctx = this._getSnapshotContext();
|
|
8546
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-Dm5ER1nI.js'); });
|
|
8547
|
+
await assertItemOwned({
|
|
8548
|
+
seedLocalId: ctx?.seedLocalId ?? undefined,
|
|
8549
|
+
seedUid: ctx?.seedUid ?? undefined,
|
|
8550
|
+
});
|
|
8377
8551
|
await xstate.waitFor(this._service, (snapshot) => !snapshot.context.isSaving && snapshot.value === 'idle', {
|
|
8378
8552
|
timeout: 10000,
|
|
8379
8553
|
});
|
|
8380
|
-
const ctx = this._getSnapshotContext();
|
|
8381
8554
|
const canonicalId = ctx?.seedLocalId ?? ctx?.seedUid;
|
|
8382
8555
|
if (canonicalId) {
|
|
8383
8556
|
eventEmitter.emit('itemProperty.saved', { seedLocalId: ctx.seedLocalId, seedUid: ctx.seedUid });
|
|
@@ -8503,11 +8676,18 @@ const createNewItem = async ({ modelName, ...propertyData }) => {
|
|
|
8503
8676
|
const { Model } = modelMod;
|
|
8504
8677
|
const model = await Model.getByNameAsync(modelName);
|
|
8505
8678
|
const propertySchemas = model?.properties ? modelPropertiesToObject(model.properties) : undefined;
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8679
|
+
// Build set of all properties to create metadata for: union of model schema + propertyData
|
|
8680
|
+
// This ensures we create metadata for ALL model properties even when creating with no initial values
|
|
8681
|
+
// (fixes first-item persistence: loadOrCreateItem needs metadata rows to run createItemPropertyInstances)
|
|
8682
|
+
const allPropertyNames = new Set(Object.keys(propertyData));
|
|
8683
|
+
if (propertySchemas) {
|
|
8684
|
+
for (const name of Object.keys(propertySchemas)) {
|
|
8685
|
+
allPropertyNames.add(name);
|
|
8686
|
+
}
|
|
8687
|
+
}
|
|
8688
|
+
for (const propertyName of allPropertyNames) {
|
|
8689
|
+
const propertyValue = propertyData[propertyName];
|
|
8690
|
+
const propertyRecordSchema = propertySchemas?.[propertyName];
|
|
8511
8691
|
await createMetadata({
|
|
8512
8692
|
seedLocalId: newSeedId,
|
|
8513
8693
|
versionLocalId: newVersionId,
|
|
@@ -8674,6 +8854,8 @@ class Item {
|
|
|
8674
8854
|
});
|
|
8675
8855
|
};
|
|
8676
8856
|
this.publish = async () => {
|
|
8857
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-Dm5ER1nI.js'); });
|
|
8858
|
+
await assertItemOwned(this);
|
|
8677
8859
|
this._service.send({ type: 'startPublish' });
|
|
8678
8860
|
return new Promise((resolve, reject) => {
|
|
8679
8861
|
let wasPublishing = false;
|
|
@@ -8708,13 +8890,13 @@ class Item {
|
|
|
8708
8890
|
};
|
|
8709
8891
|
this.getPublishUploads = async () => {
|
|
8710
8892
|
// Use dynamic import to break circular dependency
|
|
8711
|
-
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-
|
|
8893
|
+
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-DDsT9zZ6.js'); });
|
|
8712
8894
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
8713
8895
|
return await getPublishUploads(this);
|
|
8714
8896
|
};
|
|
8715
8897
|
this.getPublishPayload = async (uploadedTransactions) => {
|
|
8716
8898
|
// Use dynamic import to break circular dependency
|
|
8717
|
-
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-
|
|
8899
|
+
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-CoLriAMV.js'); });
|
|
8718
8900
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
8719
8901
|
return await getPublishPayload(this, uploadedTransactions);
|
|
8720
8902
|
};
|
|
@@ -9245,8 +9427,8 @@ class Item {
|
|
|
9245
9427
|
}
|
|
9246
9428
|
}
|
|
9247
9429
|
static async all(modelName, deleted, options) {
|
|
9248
|
-
const { waitForReady = false, readyTimeout = 5000 } = options ?? {};
|
|
9249
|
-
const itemsData = await getItemsData({ modelName, deleted });
|
|
9430
|
+
const { waitForReady = false, readyTimeout = 5000, includeEas = false, addressFilter, } = options ?? {};
|
|
9431
|
+
const itemsData = await getItemsData({ modelName, deleted, includeEas, addressFilter });
|
|
9250
9432
|
const itemInstances = [];
|
|
9251
9433
|
for (const itemData of itemsData) {
|
|
9252
9434
|
itemInstances.push(await Item.create({
|
|
@@ -9862,6 +10044,8 @@ class Item {
|
|
|
9862
10044
|
* Destroy the item: soft delete in DB, remove from caches, clean up subscriptions, stop service.
|
|
9863
10045
|
*/
|
|
9864
10046
|
async destroy() {
|
|
10047
|
+
const { assertItemOwned } = await Promise.resolve().then(function () { return require('./ownership-Dm5ER1nI.js'); });
|
|
10048
|
+
await assertItemOwned(this);
|
|
9865
10049
|
const context = this._getSnapshotContext();
|
|
9866
10050
|
const cacheKey = context.seedUid || context.seedLocalId;
|
|
9867
10051
|
const cacheKeys = cacheKey ? [cacheKey] : [];
|
|
@@ -9903,6 +10087,24 @@ class ConflictError extends Error {
|
|
|
9903
10087
|
}
|
|
9904
10088
|
}
|
|
9905
10089
|
|
|
10090
|
+
/**
|
|
10091
|
+
* Normalizes AddressConfiguration to { owned, watched }.
|
|
10092
|
+
* - string[] -> { owned: addresses, watched: [] }
|
|
10093
|
+
* - { owned, watched? } -> { owned, watched: watched ?? [] }
|
|
10094
|
+
*/
|
|
10095
|
+
function normalizeAddressConfig(addresses) {
|
|
10096
|
+
if (!addresses) {
|
|
10097
|
+
return { owned: [], watched: [] };
|
|
10098
|
+
}
|
|
10099
|
+
if (Array.isArray(addresses)) {
|
|
10100
|
+
return { owned: addresses, watched: [] };
|
|
10101
|
+
}
|
|
10102
|
+
return {
|
|
10103
|
+
owned: addresses.owned ?? [],
|
|
10104
|
+
watched: addresses.watched ?? [],
|
|
10105
|
+
};
|
|
10106
|
+
}
|
|
10107
|
+
|
|
9906
10108
|
const isNode = () => {
|
|
9907
10109
|
return (typeof process !== 'undefined' &&
|
|
9908
10110
|
process.versions != null &&
|
|
@@ -10042,6 +10244,7 @@ const saveEasSeedsToDb = async ({ itemSeeds }) => {
|
|
|
10042
10244
|
uid: seed.id,
|
|
10043
10245
|
schemaUid: seed.schemaId,
|
|
10044
10246
|
type: seed.schema.schemaNames[0].name,
|
|
10247
|
+
publisher: seed.attester,
|
|
10045
10248
|
createdAt: Date.now(),
|
|
10046
10249
|
attestationCreatedAt: seed.timeCreated * 1000,
|
|
10047
10250
|
attestationRaw,
|
|
@@ -10361,6 +10564,10 @@ const getRelatedSeedsAndVersions = async () => {
|
|
|
10361
10564
|
});
|
|
10362
10565
|
};
|
|
10363
10566
|
const syncDbWithEasHandler = lodashEs.throttle(async (_) => {
|
|
10567
|
+
const addresses = await getAllAddressesFromDb();
|
|
10568
|
+
if (!addresses || addresses.length === 0) {
|
|
10569
|
+
return;
|
|
10570
|
+
}
|
|
10364
10571
|
const appDb = BaseDb.getAppDb();
|
|
10365
10572
|
const { schemaStringToModelRecord } = await getModelSchemas();
|
|
10366
10573
|
const modelSchemas = await getModelSchemasFromEas();
|
|
@@ -10398,7 +10605,6 @@ const syncDbWithEasHandler = lodashEs.throttle(async (_) => {
|
|
|
10398
10605
|
if (schemaUids.length === 0) {
|
|
10399
10606
|
return;
|
|
10400
10607
|
}
|
|
10401
|
-
const addresses = await getAddressesFromDb();
|
|
10402
10608
|
const itemSeeds = await getSeedsFromSchemaUids({
|
|
10403
10609
|
schemaUids,
|
|
10404
10610
|
addresses,
|
|
@@ -10574,11 +10780,14 @@ const platformClassesInit = xstate.fromCallback(({ sendBack, input: { context, e
|
|
|
10574
10780
|
}
|
|
10575
10781
|
// If it's an absolute path that exists or is a valid filesystem path, use it as-is
|
|
10576
10782
|
}
|
|
10783
|
+
const normalizedAddresses = normalizeAddressConfig(addresses);
|
|
10577
10784
|
sendBack({ type: 'updateContext', context: {
|
|
10578
10785
|
models: models || {},
|
|
10579
10786
|
endpoints,
|
|
10580
10787
|
arweaveDomain,
|
|
10581
|
-
addresses:
|
|
10788
|
+
addresses: normalizedAddresses.owned,
|
|
10789
|
+
ownedAddresses: normalizedAddresses.owned,
|
|
10790
|
+
watchedAddresses: normalizedAddresses.watched,
|
|
10582
10791
|
filesDir: normalizedFilesDir,
|
|
10583
10792
|
dbConfig,
|
|
10584
10793
|
} });
|
|
@@ -10762,7 +10971,7 @@ const downloadAllFilesRequestHandler = async ({ endpoints, eventId, }) => {
|
|
|
10762
10971
|
const downloadAllFilesBinaryRequestHandler = async () => {
|
|
10763
10972
|
let addresses;
|
|
10764
10973
|
if (BaseDb.isAppDbReady()) {
|
|
10765
|
-
addresses = await
|
|
10974
|
+
addresses = await getAllAddressesFromDb();
|
|
10766
10975
|
}
|
|
10767
10976
|
if (!BaseDb.isAppDbReady()) {
|
|
10768
10977
|
// Wait for ClientManager to be ready (DB_INIT state or later)
|
|
@@ -10779,7 +10988,7 @@ const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
10779
10988
|
state === 'addModelsToDb' ||
|
|
10780
10989
|
state === 'idle';
|
|
10781
10990
|
}, { timeout: 30000 });
|
|
10782
|
-
addresses = await
|
|
10991
|
+
addresses = await getAllAddressesFromDb();
|
|
10783
10992
|
}
|
|
10784
10993
|
if (!addresses || addresses.length === 0) {
|
|
10785
10994
|
return;
|
|
@@ -11131,7 +11340,7 @@ const addModelsToDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
11131
11340
|
const logger$a = debug('seedSdk:client:actors:saveConfig');
|
|
11132
11341
|
const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
11133
11342
|
logger$a('saveConfig starting');
|
|
11134
|
-
const { endpoints, addresses, arweaveDomain } = context;
|
|
11343
|
+
const { endpoints, addresses, ownedAddresses, watchedAddresses, arweaveDomain } = context;
|
|
11135
11344
|
// Validate endpoints - required for proper initialization
|
|
11136
11345
|
// If endpoints are missing or invalid, initialization should fail
|
|
11137
11346
|
if (!endpoints || !endpoints.filePaths || !endpoints.files) {
|
|
@@ -11151,7 +11360,9 @@ const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
11151
11360
|
throw new Error('App DB not found');
|
|
11152
11361
|
}
|
|
11153
11362
|
const endpointsValueString = JSON.stringify(endpoints);
|
|
11154
|
-
const
|
|
11363
|
+
const owned = ownedAddresses ?? addresses ?? [];
|
|
11364
|
+
const watched = watchedAddresses ?? [];
|
|
11365
|
+
const addressesValueString = JSON.stringify({ owned, watched });
|
|
11155
11366
|
// TODO: Figure out how to define on conflict with multiple rows added
|
|
11156
11367
|
await appDb
|
|
11157
11368
|
.insert(appState)
|
|
@@ -11165,7 +11376,7 @@ const saveConfig = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
11165
11376
|
value: endpointsValueString,
|
|
11166
11377
|
},
|
|
11167
11378
|
});
|
|
11168
|
-
if (
|
|
11379
|
+
if (owned.length > 0 || watched.length > 0) {
|
|
11169
11380
|
await appDb
|
|
11170
11381
|
.insert(appState)
|
|
11171
11382
|
.values({
|
|
@@ -13136,14 +13347,17 @@ const clientManagerMachine = xstate.setup({
|
|
|
13136
13347
|
actions: [
|
|
13137
13348
|
xstate.assign(({ event, spawn }) => {
|
|
13138
13349
|
const { addresses } = event;
|
|
13350
|
+
const normalized = normalizeAddressConfig(addresses);
|
|
13139
13351
|
spawn('saveAppState', {
|
|
13140
13352
|
input: {
|
|
13141
13353
|
key: 'addresses',
|
|
13142
|
-
value:
|
|
13354
|
+
value: { owned: normalized.owned, watched: normalized.watched },
|
|
13143
13355
|
},
|
|
13144
13356
|
});
|
|
13145
13357
|
return {
|
|
13146
|
-
addresses,
|
|
13358
|
+
addresses: normalized.owned,
|
|
13359
|
+
ownedAddresses: normalized.owned,
|
|
13360
|
+
watchedAddresses: normalized.watched,
|
|
13147
13361
|
isSaving: true,
|
|
13148
13362
|
};
|
|
13149
13363
|
})
|
|
@@ -13216,6 +13430,8 @@ const clientInstance = {
|
|
|
13216
13430
|
isSaving: false,
|
|
13217
13431
|
endpoints: undefined,
|
|
13218
13432
|
addresses: undefined,
|
|
13433
|
+
ownedAddresses: undefined,
|
|
13434
|
+
watchedAddresses: undefined,
|
|
13219
13435
|
models: undefined,
|
|
13220
13436
|
arweaveDomain: undefined,
|
|
13221
13437
|
filesDir: undefined,
|
|
@@ -13270,9 +13486,17 @@ const clientInstance = {
|
|
|
13270
13486
|
},
|
|
13271
13487
|
getAddresses: async () => {
|
|
13272
13488
|
ensureInitialized();
|
|
13273
|
-
const
|
|
13274
|
-
const
|
|
13275
|
-
return
|
|
13489
|
+
const owned = await getOwnedAddressesFromDb();
|
|
13490
|
+
const watched = await getWatchedAddressesFromDb();
|
|
13491
|
+
return { owned, watched };
|
|
13492
|
+
},
|
|
13493
|
+
getOwnedAddresses: async () => {
|
|
13494
|
+
ensureInitialized();
|
|
13495
|
+
return getOwnedAddressesFromDb();
|
|
13496
|
+
},
|
|
13497
|
+
getWatchedAddresses: async () => {
|
|
13498
|
+
ensureInitialized();
|
|
13499
|
+
return getWatchedAddressesFromDb();
|
|
13276
13500
|
},
|
|
13277
13501
|
addModel: async (modelDef) => {
|
|
13278
13502
|
const db = await BaseDb.getAppDb();
|
|
@@ -13482,7 +13706,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
|
|
|
13482
13706
|
// Lazy import cache for ModelProperty to avoid circular dependency
|
|
13483
13707
|
// Eagerly start loading to minimize delay on first access
|
|
13484
13708
|
let ModelPropertyClass = null;
|
|
13485
|
-
const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-
|
|
13709
|
+
const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-DpjD0o0E.js'); })
|
|
13486
13710
|
.then(module => {
|
|
13487
13711
|
ModelPropertyClass = module.ModelProperty;
|
|
13488
13712
|
return ModelPropertyClass;
|
|
@@ -13499,7 +13723,7 @@ function getModelProperty() {
|
|
|
13499
13723
|
}
|
|
13500
13724
|
// Lazy import cache for Schema to avoid circular dependency
|
|
13501
13725
|
let SchemaClass = null;
|
|
13502
|
-
const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-
|
|
13726
|
+
const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-DkSBMBwz.js'); }).then(function (n) { return n.Schema$1; })
|
|
13503
13727
|
.then(module => {
|
|
13504
13728
|
SchemaClass = module.Schema;
|
|
13505
13729
|
return SchemaClass;
|
|
@@ -14015,7 +14239,11 @@ class Model {
|
|
|
14015
14239
|
// Step 11: Register with schema if requested, OR trigger write if properties are provided
|
|
14016
14240
|
// If properties are provided, we need to write the model to get modelId for property creation
|
|
14017
14241
|
// If schema provided, trigger write process instead of registration
|
|
14018
|
-
|
|
14242
|
+
// When schemaName is passed as string (e.g. useCreateModel), we must trigger write so runtime-created
|
|
14243
|
+
// models get persisted to DB and show up in useModels (which queries the database).
|
|
14244
|
+
const shouldTriggerWrite = (registerWithSchema && schemaInstance) ||
|
|
14245
|
+
(options?.properties && Object.keys(options.properties).length > 0) ||
|
|
14246
|
+
typeof schemaNameOrSchema === 'string';
|
|
14019
14247
|
if (shouldTriggerWrite) {
|
|
14020
14248
|
queueMicrotask(async () => {
|
|
14021
14249
|
try {
|
|
@@ -14298,6 +14526,22 @@ class Model {
|
|
|
14298
14526
|
}
|
|
14299
14527
|
return undefined;
|
|
14300
14528
|
}
|
|
14529
|
+
/**
|
|
14530
|
+
* Find Model by modelType (snake_case from DB/metadata).
|
|
14531
|
+
* Handles model names with spaces: "new_model" -> finds "New model" (toSnakeCase("New model") === "new_model").
|
|
14532
|
+
*/
|
|
14533
|
+
static findByModelType(modelType) {
|
|
14534
|
+
if (!modelType)
|
|
14535
|
+
return undefined;
|
|
14536
|
+
for (const [nameKey, id] of this.instanceCacheByName.entries()) {
|
|
14537
|
+
const parts = nameKey.split(':', 2);
|
|
14538
|
+
const cachedModelName = parts[1];
|
|
14539
|
+
if (cachedModelName && casing.toSnakeCase(cachedModelName) === modelType) {
|
|
14540
|
+
return this.getById(id);
|
|
14541
|
+
}
|
|
14542
|
+
}
|
|
14543
|
+
return undefined;
|
|
14544
|
+
}
|
|
14301
14545
|
/**
|
|
14302
14546
|
* Get all Model instances for a schema from cache only (synchronous).
|
|
14303
14547
|
* Includes models created at runtime via Model.create() that may not yet be in schema context.
|
|
@@ -15534,105 +15778,6 @@ class Db extends BaseDb {
|
|
|
15534
15778
|
// You can inspect what will happen before applying
|
|
15535
15779
|
await apply();
|
|
15536
15780
|
this.db = db;
|
|
15537
|
-
// OLD CODE: Resolve better-sqlite3 from project's node_modules first, then fall back to SDK's node_modules
|
|
15538
|
-
// This is important for tests and when the SDK is used as a dependency
|
|
15539
|
-
// const projectDir = path.dirname(filesDir) // filesDir is .seed, so projectDir is the project root
|
|
15540
|
-
// const projectBetterSqlite3Path = path.join(projectDir, 'node_modules', 'better-sqlite3')
|
|
15541
|
-
//
|
|
15542
|
-
// let Database: any
|
|
15543
|
-
// try {
|
|
15544
|
-
// const fs = await import('fs')
|
|
15545
|
-
// if (fs.existsSync(projectBetterSqlite3Path)) {
|
|
15546
|
-
// // Try to resolve from project's node_modules using the full path
|
|
15547
|
-
// // For Bun, we can try importing directly from the path
|
|
15548
|
-
// try {
|
|
15549
|
-
// // First try using createRequire (works in Node.js)
|
|
15550
|
-
// const { createRequire } = await import('module')
|
|
15551
|
-
// const projectRequire = createRequire(path.join(projectDir, 'package.json'))
|
|
15552
|
-
// const betterSqlite3Module = projectRequire('better-sqlite3')
|
|
15553
|
-
// Database = betterSqlite3Module.default || betterSqlite3Module
|
|
15554
|
-
// logger('[node/db/Db] Using better-sqlite3 from project node_modules via createRequire')
|
|
15555
|
-
// } catch (requireError: any) {
|
|
15556
|
-
// // If createRequire fails (e.g., in Bun), try direct path import
|
|
15557
|
-
// logger('[node/db/Db] createRequire failed, trying direct import:', requireError.message)
|
|
15558
|
-
// const betterSqlite3MainPath = path.join(projectBetterSqlite3Path, 'lib', 'database.js')
|
|
15559
|
-
// if (fs.existsSync(betterSqlite3MainPath)) {
|
|
15560
|
-
// // Use dynamic import with the full path
|
|
15561
|
-
// const betterSqlite3Module = await import(betterSqlite3MainPath)
|
|
15562
|
-
// Database = betterSqlite3Module.default || betterSqlite3Module.Database || betterSqlite3Module
|
|
15563
|
-
// logger('[node/db/Db] Using better-sqlite3 from project node_modules via direct import')
|
|
15564
|
-
// } else {
|
|
15565
|
-
// throw new Error(`better-sqlite3 main file not found at ${betterSqlite3MainPath}`)
|
|
15566
|
-
// }
|
|
15567
|
-
// }
|
|
15568
|
-
// } else {
|
|
15569
|
-
// // Fall back to regular import (from SDK's node_modules)
|
|
15570
|
-
// const betterSqlite3Module = await import('better-sqlite3')
|
|
15571
|
-
// Database = betterSqlite3Module.default || betterSqlite3Module
|
|
15572
|
-
// logger('[node/db/Db] Using better-sqlite3 from SDK node_modules')
|
|
15573
|
-
// }
|
|
15574
|
-
// } catch (importError: any) {
|
|
15575
|
-
// logger('[node/db/Db] Error importing better-sqlite3:', importError.message)
|
|
15576
|
-
// logger('[node/db/Db] projectDir:', projectDir)
|
|
15577
|
-
// logger('[node/db/Db] projectBetterSqlite3Path:', projectBetterSqlite3Path)
|
|
15578
|
-
// throw new Error(`Failed to import better-sqlite3: ${importError.message}. Please install better-sqlite3 in your project.`)
|
|
15579
|
-
// }
|
|
15580
|
-
// OLD CODE: Create Database instance
|
|
15581
|
-
// const sqlite = new Database(dbPath)
|
|
15582
|
-
//
|
|
15583
|
-
// OLD CODE: Create drizzle instance with the Database
|
|
15584
|
-
// const {drizzle} = await import('drizzle-orm/better-sqlite3')
|
|
15585
|
-
// this.db = drizzle(sqlite, {
|
|
15586
|
-
// logger: true,
|
|
15587
|
-
// })
|
|
15588
|
-
// // NEW CODE: Use libsql instead of better-sqlite3
|
|
15589
|
-
// // Resolve @libsql/client from project's node_modules first, then fall back to SDK's node_modules
|
|
15590
|
-
// const projectDir = path.dirname(filesDir) // filesDir is .seed, so projectDir is the project root
|
|
15591
|
-
// const projectLibsqlClientPath = path.join(projectDir, 'node_modules', '@libsql', 'client')
|
|
15592
|
-
// let createClient: any
|
|
15593
|
-
// try {
|
|
15594
|
-
// const fs = await import('fs')
|
|
15595
|
-
// if (fs.existsSync(projectLibsqlClientPath)) {
|
|
15596
|
-
// // Try to resolve from project's node_modules using the full path
|
|
15597
|
-
// try {
|
|
15598
|
-
// // First try using createRequire (works in Node.js)
|
|
15599
|
-
// const { createRequire } = await import('module')
|
|
15600
|
-
// const projectRequire = createRequire(path.join(projectDir, 'package.json'))
|
|
15601
|
-
// const libsqlClientModule = projectRequire('@libsql/client')
|
|
15602
|
-
// createClient = libsqlClientModule.createClient || libsqlClientModule.default?.createClient || libsqlClientModule.default
|
|
15603
|
-
// logger('[node/db/Db] Using @libsql/client from project node_modules via createRequire')
|
|
15604
|
-
// } catch (requireError: any) {
|
|
15605
|
-
// // If createRequire fails, try direct import
|
|
15606
|
-
// logger('[node/db/Db] createRequire failed, trying direct import:', requireError.message)
|
|
15607
|
-
// const libsqlClientModule = await import('@libsql/client')
|
|
15608
|
-
// createClient = libsqlClientModule.createClient
|
|
15609
|
-
// logger('[node/db/Db] Using @libsql/client from project node_modules via direct import')
|
|
15610
|
-
// }
|
|
15611
|
-
// } else {
|
|
15612
|
-
// // Fall back to regular import (from SDK's node_modules)
|
|
15613
|
-
// const libsqlClientModule = await import('@libsql/client')
|
|
15614
|
-
// createClient = libsqlClientModule.createClient
|
|
15615
|
-
// logger('[node/db/Db] Using @libsql/client from SDK node_modules')
|
|
15616
|
-
// }
|
|
15617
|
-
// } catch (importError: any) {
|
|
15618
|
-
// logger('[node/db/Db] Error importing @libsql/client:', importError.message)
|
|
15619
|
-
// logger('[node/db/Db] projectDir:', projectDir)
|
|
15620
|
-
// logger('[node/db/Db] projectLibsqlClientPath:', projectLibsqlClientPath)
|
|
15621
|
-
// throw new Error(`Failed to import @libsql/client: ${importError.message}. Please install @libsql/client in your project.`)
|
|
15622
|
-
// }
|
|
15623
|
-
// // Convert file path to file: URL for libsql
|
|
15624
|
-
// // If dbPath is already a file: URL, use it as is, otherwise convert it
|
|
15625
|
-
// const dbUrl = dbPath.startsWith('file:') ? dbPath : `file:${path.resolve(dbPath)}`
|
|
15626
|
-
// // Create libsql client instance
|
|
15627
|
-
// const client = createClient({ url: dbUrl })
|
|
15628
|
-
// // Create drizzle instance with the libsql client
|
|
15629
|
-
// const {drizzle} = await import('drizzle-orm/libsql')
|
|
15630
|
-
// this.db = drizzle(client, {
|
|
15631
|
-
// logger: true,
|
|
15632
|
-
// })
|
|
15633
|
-
// if (!this.db) {
|
|
15634
|
-
// throw new Error('Db not found')
|
|
15635
|
-
// }
|
|
15636
15781
|
return this.db;
|
|
15637
15782
|
}
|
|
15638
15783
|
static async connectToDb(pathToDir) {
|
|
@@ -16250,7 +16395,7 @@ const getTsImport = async (filePath) => {
|
|
|
16250
16395
|
|
|
16251
16396
|
// Get the directory of this file to resolve relative paths
|
|
16252
16397
|
// @ts-ignore - rollup plugin-typescript doesn't recognize import.meta with module: "preserve"
|
|
16253
|
-
const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-
|
|
16398
|
+
const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-B95Ng80C.js', document.baseURI).href)));
|
|
16254
16399
|
path.dirname(__filename$1);
|
|
16255
16400
|
const commandExists = (command) => {
|
|
16256
16401
|
try {
|
|
@@ -16767,6 +16912,7 @@ exports.getItemData = getItemData;
|
|
|
16767
16912
|
exports.getLatestSchemaVersion = getLatestSchemaVersion;
|
|
16768
16913
|
exports.getModelId = getModelId;
|
|
16769
16914
|
exports.getModelIdByFileId = getModelIdByFileId;
|
|
16915
|
+
exports.getOwnedAddressesFromDb = getOwnedAddressesFromDb;
|
|
16770
16916
|
exports.getSchemaForItemProperty = getSchemaForItemProperty;
|
|
16771
16917
|
exports.getSchemaUidForModel = getSchemaUidForModel;
|
|
16772
16918
|
exports.getSchemaUidForSchemaDefinition = getSchemaUidForSchemaDefinition;
|
|
@@ -16801,4 +16947,4 @@ exports.versions = versions;
|
|
|
16801
16947
|
exports.waitForEntityIdle = waitForEntityIdle;
|
|
16802
16948
|
exports.withSeed = withSeed;
|
|
16803
16949
|
exports.writeProcessMachine = writeProcessMachine;
|
|
16804
|
-
//# sourceMappingURL=index-
|
|
16950
|
+
//# sourceMappingURL=index-B95Ng80C.js.map
|