@seedprotocol/sdk 0.7.0 → 0.7.2-next.593.gd5bd4ea
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-ndE8XTpw.js → BasePathResolver-BdxCSIzn.js} +2 -2
- package/dist/{BasePathResolver-ndE8XTpw.js.map → BasePathResolver-BdxCSIzn.js.map} +1 -1
- package/dist/{ClientManager-DLleL_2e.js → ClientManager-ClCwwhwo.js} +28 -23
- package/dist/ClientManager-ClCwwhwo.js.map +1 -0
- package/dist/{Item-zBFWQDU9.js → Item-B9Y4VuK1.js} +140 -74
- package/dist/Item-B9Y4VuK1.js.map +1 -0
- package/dist/{ModelProperty-lth9L37R.js → ModelProperty-BMePcicQ.js} +64 -36
- package/dist/ModelProperty-BMePcicQ.js.map +1 -0
- package/dist/{Schema-DOhlrQ-N.js → Schema-COsEXXaR.js} +106 -58
- package/dist/Schema-COsEXXaR.js.map +1 -0
- package/dist/{SchemaValidationService-DDKr5piy.js → SchemaValidationService-DabGMzSE.js} +7 -8
- package/dist/{SchemaValidationService-DDKr5piy.js.map → SchemaValidationService-DabGMzSE.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-fG3ujaSh.js → backfillMetadataPropertyIds-Ck6fumnm.js} +4 -4
- package/dist/{backfillMetadataPropertyIds-fG3ujaSh.js.map → backfillMetadataPropertyIds-Ck6fumnm.js.map} +1 -1
- package/dist/cjs/{ModelProperty-BEsIHAjk.js → ModelProperty-BT6Un_MB.js} +59 -30
- package/dist/cjs/ModelProperty-BT6Un_MB.js.map +1 -0
- package/dist/cjs/{Schema-qEp5mH1N.js → Schema-BXhXdUsA.js} +93 -44
- package/dist/cjs/Schema-BXhXdUsA.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-CWEnZmOH.js → SchemaValidationService-CC18QDfc.js} +2 -2
- package/dist/cjs/{SchemaValidationService-CWEnZmOH.js.map → SchemaValidationService-CC18QDfc.js.map} +1 -1
- package/dist/cjs/{backfillMetadataPropertyIds-tw8JGMT0.js → backfillMetadataPropertyIds-DEHC9ejq.js} +3 -3
- package/dist/cjs/{backfillMetadataPropertyIds-tw8JGMT0.js.map → backfillMetadataPropertyIds-DEHC9ejq.js.map} +1 -1
- package/dist/cjs/{eas-CLiV2Hmn.js → eas-C3CL0l7l.js} +3 -3
- package/dist/cjs/{eas-CLiV2Hmn.js.map → eas-C3CL0l7l.js.map} +1 -1
- package/dist/cjs/{getItem-DSRtx_68.js → getItem-CrwWYCkj.js} +2 -2
- package/dist/cjs/{getItem-DSRtx_68.js.map → getItem-CrwWYCkj.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-D5-dYtNq.js → getPublishPayload-DRJh7WR0.js} +171 -209
- package/dist/cjs/getPublishPayload-DRJh7WR0.js.map +1 -0
- package/dist/cjs/{getPublishUploads-B5Lq6q-_.js → getPublishUploads-Bh22D3zJ.js} +49 -10
- package/dist/cjs/getPublishUploads-Bh22D3zJ.js.map +1 -0
- package/dist/cjs/{index-B3UDbm1C.js → index-BA1RIYFG.js} +3 -3
- package/dist/cjs/index-BA1RIYFG.js.map +1 -0
- package/dist/cjs/{index-C66AfYDG.js → index-Dls7aMjr.js} +281 -90
- package/dist/cjs/index-Dls7aMjr.js.map +1 -0
- package/dist/cjs/{property-BVJIP7SX.js → property-ZerTWizX.js} +5 -5
- package/dist/cjs/{property-BVJIP7SX.js.map → property-ZerTWizX.js.map} +1 -1
- package/dist/cjs/publishDraftGraph-CPOAcQFf.js +403 -0
- package/dist/cjs/publishDraftGraph-CPOAcQFf.js.map +1 -0
- package/dist/cjs/{resetAmbiguousLegacyItemData-BaZqUui9.js → resetAmbiguousLegacyItemData-adDl4LcT.js} +2 -2
- package/dist/cjs/{resetAmbiguousLegacyItemData-BaZqUui9.js.map → resetAmbiguousLegacyItemData-adDl4LcT.js.map} +1 -1
- package/dist/cjs/{resolveModelForSyncedSeed-CC6dQctx.js → resolveModelForSyncedSeed-DoNThPdL.js} +2 -2
- package/dist/cjs/{resolveModelForSyncedSeed-CC6dQctx.js.map → resolveModelForSyncedSeed-DoNThPdL.js.map} +1 -1
- package/dist/cjs/{syncDbWithEas-Dk96sAG-.js → syncDbWithEas-CYfPkus9.js} +20 -7
- package/dist/cjs/{syncDbWithEas-Dk96sAG-.js.map → syncDbWithEas-CYfPkus9.js.map} +1 -1
- package/dist/{configurePlatform-BMoPG9vY.js → configurePlatform-xU3Hsno3.js} +4 -4
- package/dist/{configurePlatform-BMoPG9vY.js.map → configurePlatform-xU3Hsno3.js.map} +1 -1
- package/dist/{db-BJZN0a0a.js → db-W1g29qsM.js} +31 -27
- package/dist/{db-BJZN0a0a.js.map → db-W1g29qsM.js.map} +1 -1
- package/dist/{eas-B0hsMLqt.js → eas-CSwV6MvB.js} +6 -6
- package/dist/{eas-B0hsMLqt.js.map → eas-CSwV6MvB.js.map} +1 -1
- package/dist/{getItem-DEh4WfHG.js → getItem-BYQeM3DY.js} +5 -6
- package/dist/{getItem-DEh4WfHG.js.map → getItem-BYQeM3DY.js.map} +1 -1
- package/dist/{getPublishPayload-H032DHC7.js → getPublishPayload-D5CQZd-y.js} +167 -206
- package/dist/getPublishPayload-D5CQZd-y.js.map +1 -0
- package/dist/{getPublishUploads-CR66RlGJ.js → getPublishUploads-BGpDsrBp.js} +52 -14
- package/dist/getPublishUploads-BGpDsrBp.js.map +1 -0
- package/dist/{index-6bJuv5Tt.js → index-Bev-hZF-.js} +9 -10
- package/dist/index-Bev-hZF-.js.map +1 -0
- package/dist/{index-B0LgJblD.js → index-CSOQFAOn.js} +2 -2
- package/dist/index-CSOQFAOn.js.map +1 -0
- package/dist/{index-DtfjeuxC.js → index-DRXC5Mra.js} +167 -75
- package/dist/index-DRXC5Mra.js.map +1 -0
- package/dist/{index.browser-CNrqhvEA.js → index.browser-DO20vYuP.js} +9 -9
- package/dist/{index.browser-CNrqhvEA.js.map → index.browser-DO20vYuP.js.map} +1 -1
- package/dist/{index.node-DrHiTuOr.js → index.node-C4iyOhdo.js} +5 -5
- package/dist/{index.node-DrHiTuOr.js.map → index.node-C4iyOhdo.js.map} +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.js +258 -183
- package/dist/main.js.map +1 -1
- package/dist/node.js +14 -15
- package/dist/node.js.map +1 -1
- package/dist/platform.browser.js +5 -5
- package/dist/platform.node.js +3 -3
- package/dist/{property-D2Nnsmm1.js → property-BT1zDSkd.js} +10 -11
- package/dist/property-BT1zDSkd.js.map +1 -0
- package/dist/publishDraftGraph-Bcfrdj7-.js +405 -0
- package/dist/publishDraftGraph-Bcfrdj7-.js.map +1 -0
- package/dist/{resetAmbiguousLegacyItemData-BqbHNUYk.js → resetAmbiguousLegacyItemData-Ci6PM_vC.js} +2 -2
- package/dist/{resetAmbiguousLegacyItemData-BqbHNUYk.js.map → resetAmbiguousLegacyItemData-Ci6PM_vC.js.map} +1 -1
- package/dist/{resolveModelForSyncedSeed-DQK6JfXS.js → resolveModelForSyncedSeed-CLlumTBq.js} +2 -2
- package/dist/{resolveModelForSyncedSeed-DQK6JfXS.js.map → resolveModelForSyncedSeed-CLlumTBq.js.map} +1 -1
- package/dist/src/Item/Item.d.ts +11 -0
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +10 -0
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/Model/Model.d.ts +15 -2
- package/dist/src/Model/Model.d.ts.map +1 -1
- package/dist/src/Model/service/actors/createModelProperties.d.ts.map +1 -1
- package/dist/src/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
- package/dist/src/Model/service/actors/validateModel.d.ts.map +1 -1
- package/dist/src/Model/service/modelMachine.d.ts.map +1 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts +9 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/saveToSchema.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
- package/dist/src/Schema/Schema.d.ts +7 -0
- package/dist/src/Schema/Schema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/createModelInstances.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.d.ts +9 -0
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts +5 -0
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/publishDraftGraph.d.ts +57 -0
- package/dist/src/db/read/publishDraftGraph.d.ts.map +1 -0
- package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
- package/dist/src/helpers/entity/evictionEpoch.d.ts +18 -0
- package/dist/src/helpers/entity/evictionEpoch.d.ts.map +1 -0
- package/dist/src/helpers/generateId.d.ts +4 -0
- package/dist/src/helpers/generateId.d.ts.map +1 -1
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +28 -6
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/query/createLocalQueryDataSource.d.ts.map +1 -1
- package/dist/src/services/write/actors/validateEntity.d.ts.map +1 -1
- package/dist/src/types/item.d.ts +7 -8
- package/dist/src/types/item.d.ts.map +1 -1
- package/dist/{syncDbWithEas-LRKr_NZF.js → syncDbWithEas-BQsXjGhe.js} +15 -16
- package/dist/syncDbWithEas-BQsXjGhe.js.map +1 -0
- package/dist/{tabEvents-DYI2GU7i.js → tabEvents-C9qUKx_z.js} +28 -11
- package/dist/tabEvents-C9qUKx_z.js.map +1 -0
- package/dist/{tolerantWebAccess-CzOBz5M6.js → tolerantWebAccess-B-9bwxbw.js} +6 -6
- package/dist/{tolerantWebAccess-CzOBz5M6.js.map → tolerantWebAccess-B-9bwxbw.js.map} +1 -1
- package/dist/{updateSeedRevokedAt-B58ORbY3.js → updateSeedRevokedAt-D6q0h7pj.js} +3 -3
- package/dist/{updateSeedRevokedAt-B58ORbY3.js.map → updateSeedRevokedAt-D6q0h7pj.js.map} +1 -1
- package/package.json +13 -10
- package/dist/ClientManager-DLleL_2e.js.map +0 -1
- package/dist/Item-zBFWQDU9.js.map +0 -1
- package/dist/ModelProperty-lth9L37R.js.map +0 -1
- package/dist/Schema-DOhlrQ-N.js.map +0 -1
- package/dist/cjs/ModelProperty-BEsIHAjk.js.map +0 -1
- package/dist/cjs/Schema-qEp5mH1N.js.map +0 -1
- package/dist/cjs/getLatestVersionRow-DVizNNoI.js +0 -59
- package/dist/cjs/getLatestVersionRow-DVizNNoI.js.map +0 -1
- package/dist/cjs/getPublishPayload-D5-dYtNq.js.map +0 -1
- package/dist/cjs/getPublishUploads-B5Lq6q-_.js.map +0 -1
- package/dist/cjs/getSegmentedItemProperties-giHO7R3d.js +0 -147
- package/dist/cjs/getSegmentedItemProperties-giHO7R3d.js.map +0 -1
- package/dist/cjs/index-B3UDbm1C.js.map +0 -1
- package/dist/cjs/index-C66AfYDG.js.map +0 -1
- package/dist/generateId-BopUwD8F.js +0 -9
- package/dist/generateId-BopUwD8F.js.map +0 -1
- package/dist/getLatestVersionRow-Brrl1AnW.js +0 -46
- package/dist/getLatestVersionRow-Brrl1AnW.js.map +0 -1
- package/dist/getPublishPayload-H032DHC7.js.map +0 -1
- package/dist/getPublishUploads-CR66RlGJ.js.map +0 -1
- package/dist/getSegmentedItemProperties-C2EJ2G0N.js +0 -147
- package/dist/getSegmentedItemProperties-C2EJ2G0N.js.map +0 -1
- package/dist/index-6bJuv5Tt.js.map +0 -1
- package/dist/index-B0LgJblD.js.map +0 -1
- package/dist/index-DtfjeuxC.js.map +0 -1
- package/dist/property-D2Nnsmm1.js.map +0 -1
- package/dist/src/browser/helpers/index.d.ts +0 -4
- package/dist/src/browser/helpers/index.d.ts.map +0 -1
- package/dist/syncDbWithEas-LRKr_NZF.js.map +0 -1
- package/dist/tabEvents-DYI2GU7i.js.map +0 -1
|
@@ -377,9 +377,14 @@ let revokeExecutor = null;
|
|
|
377
377
|
function getRevokeExecutor() {
|
|
378
378
|
return revokeExecutor;
|
|
379
379
|
}
|
|
380
|
+
let getAdditionalSyncAddresses = null;
|
|
381
|
+
function getGetAdditionalSyncAddresses() {
|
|
382
|
+
return getAdditionalSyncAddresses;
|
|
383
|
+
}
|
|
380
384
|
|
|
381
385
|
var publishConfig = /*#__PURE__*/Object.freeze({
|
|
382
386
|
__proto__: null,
|
|
387
|
+
getGetAdditionalSyncAddresses: getGetAdditionalSyncAddresses,
|
|
383
388
|
getPublisherForNewSeedsWithTimeout: getPublisherForNewSeedsWithTimeout,
|
|
384
389
|
getRevokeExecutor: getRevokeExecutor,
|
|
385
390
|
getUploadExecutor: getUploadExecutor
|
|
@@ -4326,8 +4331,16 @@ const ensureImageLocal = async (params) => {
|
|
|
4326
4331
|
return inFlight;
|
|
4327
4332
|
};
|
|
4328
4333
|
|
|
4334
|
+
const randomId = nanoid.customAlphabet(nanoidDictionary.alphanumeric, 10);
|
|
4335
|
+
/**
|
|
4336
|
+
* A 10-character local id. Never starts with "0x" (about 1 in 3,844 random ids would), so code that
|
|
4337
|
+
* tells local ids from EAS uids by that prefix can't mistake one for the other.
|
|
4338
|
+
*/
|
|
4329
4339
|
const generateId = () => {
|
|
4330
|
-
|
|
4340
|
+
let id = randomId();
|
|
4341
|
+
while (id.startsWith('0x'))
|
|
4342
|
+
id = randomId();
|
|
4343
|
+
return id;
|
|
4331
4344
|
};
|
|
4332
4345
|
|
|
4333
4346
|
var generateId$1 = /*#__PURE__*/Object.freeze({
|
|
@@ -4421,6 +4434,22 @@ const convertTxIdToImage = async (txId) => {
|
|
|
4421
4434
|
return URL.createObjectURL(imageBlob);
|
|
4422
4435
|
};
|
|
4423
4436
|
|
|
4437
|
+
/**
|
|
4438
|
+
* Common getters and utilities for entity classes
|
|
4439
|
+
* These work with any entity that has a getService() method returning an XState actor
|
|
4440
|
+
*/
|
|
4441
|
+
/**
|
|
4442
|
+
* Get the current state value from an entity's service
|
|
4443
|
+
*/
|
|
4444
|
+
/**
|
|
4445
|
+
* Whether an actor has been stopped (unload, destroy, or Schema eviction). Async work started by an
|
|
4446
|
+
* entity (DB lookups, retry timers) must check this before sending, since a stopped actor ignores
|
|
4447
|
+
* events and XState warns about every one of them.
|
|
4448
|
+
*/
|
|
4449
|
+
function isActorStopped(actor) {
|
|
4450
|
+
return actor.getSnapshot().status === 'stopped';
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4424
4453
|
const logger$w = debug('seedSdk:model:actors:loadOrCreateModel');
|
|
4425
4454
|
/**
|
|
4426
4455
|
* Create ModelProperty instances for all property IDs to ensure they're cached
|
|
@@ -4432,7 +4461,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
4432
4461
|
return;
|
|
4433
4462
|
}
|
|
4434
4463
|
try {
|
|
4435
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
4464
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BT6Un_MB.js'); });
|
|
4436
4465
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
4437
4466
|
if (!ModelProperty) {
|
|
4438
4467
|
logger$w('createPropertyInstances: ModelProperty not available from dynamic import');
|
|
@@ -4463,7 +4492,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
4463
4492
|
// Don't throw - this is best-effort to pre-populate cache
|
|
4464
4493
|
}
|
|
4465
4494
|
};
|
|
4466
|
-
const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
4495
|
+
const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context }, self }) => {
|
|
4467
4496
|
const _loadOrCreateModel = async () => {
|
|
4468
4497
|
const { modelName, schemaName, id, _idFromSchema } = context; // id is now the schemaFileId (string)
|
|
4469
4498
|
if (!modelName || !schemaName) {
|
|
@@ -4602,7 +4631,9 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
4602
4631
|
.map((record) => record.schemaFileId)
|
|
4603
4632
|
.filter((id) => id !== null && id !== undefined);
|
|
4604
4633
|
if (propertyFileIds.length > 0) {
|
|
4605
|
-
|
|
4634
|
+
// Not for a model stopped meanwhile (unloaded, or evicted with its schema)
|
|
4635
|
+
if (!isActorStopped(self))
|
|
4636
|
+
await createPropertyInstances(propertyFileIds);
|
|
4606
4637
|
}
|
|
4607
4638
|
// Generate schemaFileId if not set
|
|
4608
4639
|
if (!schemaFileId) {
|
|
@@ -4643,8 +4674,11 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
4643
4674
|
// Step 2: Fallback to Schema context (only if database doesn't have the model)
|
|
4644
4675
|
// This handles the case where model exists in schema file but not yet in database
|
|
4645
4676
|
try {
|
|
4646
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
4677
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BXhXdUsA.js'); });
|
|
4647
4678
|
const { Schema } = schemaMod;
|
|
4679
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
4680
|
+
if (isActorStopped(self))
|
|
4681
|
+
return;
|
|
4648
4682
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
4649
4683
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
4650
4684
|
// Wait for schema to load if it's still loading
|
|
@@ -4885,10 +4919,12 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
4885
4919
|
}
|
|
4886
4920
|
// Mark schema as draft when a new model is created so saveNewVersion() can persist it
|
|
4887
4921
|
try {
|
|
4888
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
4922
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BXhXdUsA.js'); });
|
|
4889
4923
|
const { Schema } = schemaMod;
|
|
4890
|
-
|
|
4891
|
-
|
|
4924
|
+
if (!isActorStopped(self)) {
|
|
4925
|
+
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
4926
|
+
schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
|
|
4927
|
+
}
|
|
4892
4928
|
}
|
|
4893
4929
|
catch (err) {
|
|
4894
4930
|
logger$w(`Failed to mark schema as draft after creating model: ${err}`);
|
|
@@ -4909,7 +4945,7 @@ const loadOrCreateModel = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
4909
4945
|
const logger$v = debug('seedSdk:model:actors:validateModel');
|
|
4910
4946
|
// Validation timeout in milliseconds (10 seconds)
|
|
4911
4947
|
const VALIDATION_TIMEOUT_MS = 10000;
|
|
4912
|
-
const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
4948
|
+
const validateModel = xstate.fromCallback(({ sendBack, input: { context }, self }) => {
|
|
4913
4949
|
let hasResponded = false;
|
|
4914
4950
|
// Timeout handler to ensure we always respond
|
|
4915
4951
|
const timeoutId = setTimeout(() => {
|
|
@@ -4929,10 +4965,10 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
4929
4965
|
const _validateModel = async () => {
|
|
4930
4966
|
try {
|
|
4931
4967
|
// Use dynamic imports to break circular dependencies
|
|
4932
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
4968
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CC18QDfc.js'); });
|
|
4933
4969
|
const { SchemaValidationService } = validationServiceMod;
|
|
4934
4970
|
const validationService = new SchemaValidationService();
|
|
4935
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
4971
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-BXhXdUsA.js'); });
|
|
4936
4972
|
const { Schema } = schemaMod;
|
|
4937
4973
|
// Validate model structure
|
|
4938
4974
|
const structureResult = validationService.validateModelStructure(context);
|
|
@@ -4947,6 +4983,9 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
4947
4983
|
// If we have schema name, validate against schema
|
|
4948
4984
|
// CRITICAL: Use validateModelAgainstSchema which doesn't require the model to be in schema context
|
|
4949
4985
|
// This allows validation BEFORE registration, preventing update loops
|
|
4986
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
4987
|
+
if (isActorStopped(self))
|
|
4988
|
+
return;
|
|
4950
4989
|
if (context.schemaName) {
|
|
4951
4990
|
try {
|
|
4952
4991
|
const schema = Schema.create(context.schemaName, {
|
|
@@ -5029,7 +5068,11 @@ const validateModel = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
5029
5068
|
});
|
|
5030
5069
|
|
|
5031
5070
|
const logger$u = debug('seedSdk:model:actors:createModelProperties');
|
|
5032
|
-
const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
|
|
5071
|
+
const createModelProperties = xstate.fromCallback(({ sendBack, input, self }) => {
|
|
5072
|
+
// The model was stopped (unloaded, or evicted with its schema by Schema.destroy / test cleanup) while
|
|
5073
|
+
// this ran: stopping it stops this actor too, but can't cancel the awaits below. A stopped model
|
|
5074
|
+
// creates no properties (they'd be cached for a model that's gone, and write rows under it).
|
|
5075
|
+
const stopped = () => isActorStopped(self);
|
|
5033
5076
|
const _createProperties = async () => {
|
|
5034
5077
|
const { context, propertyDefinitions } = input;
|
|
5035
5078
|
const { id, _dbId, modelName, schemaName } = context;
|
|
@@ -5042,7 +5085,7 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
5042
5085
|
return;
|
|
5043
5086
|
}
|
|
5044
5087
|
logger$u(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
|
|
5045
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
5088
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BT6Un_MB.js'); });
|
|
5046
5089
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
5047
5090
|
if (!ModelProperty) {
|
|
5048
5091
|
logger$u('ModelProperty not available from dynamic import');
|
|
@@ -5096,6 +5139,10 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
5096
5139
|
// Continue without refModelId - it will be resolved later in _initializeOriginalValues
|
|
5097
5140
|
}
|
|
5098
5141
|
}
|
|
5142
|
+
if (stopped()) {
|
|
5143
|
+
logger$u(`Model "${modelName}" was stopped while creating its properties; not creating the rest`);
|
|
5144
|
+
return;
|
|
5145
|
+
}
|
|
5099
5146
|
// Create ModelProperty instance
|
|
5100
5147
|
// This will load from DB if it exists, or create new instance
|
|
5101
5148
|
// The property should already be in DB from writeModelToDb
|
|
@@ -5134,6 +5181,37 @@ const createModelProperties = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
5134
5181
|
};
|
|
5135
5182
|
});
|
|
5136
5183
|
|
|
5184
|
+
/**
|
|
5185
|
+
* Eviction epochs: lets work that was started before a schema's Model/ModelProperty instances were
|
|
5186
|
+
* evicted (Schema.destroy, test cleanup) tell, when it finishes, that it must not put instances for
|
|
5187
|
+
* that schema back in the caches. Stopping the evicted actors can't cancel such work (a DB lookup
|
|
5188
|
+
* that ends in Model.create, a model's property creation), and finishing it after the eviction would
|
|
5189
|
+
* rebuild instances from rows that are about to be deleted, which then write themselves again.
|
|
5190
|
+
*
|
|
5191
|
+
* Capture `currentEvictionEpoch()` when the work starts; before creating or caching an instance, skip
|
|
5192
|
+
* it when `schemaEvictedSince(schemaName, epoch)`. Work started after an eviction is unaffected.
|
|
5193
|
+
*/
|
|
5194
|
+
let epoch = 0;
|
|
5195
|
+
const lastEvictionBySchema = new Map();
|
|
5196
|
+
function currentEvictionEpoch() {
|
|
5197
|
+
return epoch;
|
|
5198
|
+
}
|
|
5199
|
+
/** Called by Model.evictForSchema. */
|
|
5200
|
+
function recordSchemaEviction(schemaName) {
|
|
5201
|
+
epoch += 1;
|
|
5202
|
+
lastEvictionBySchema.set(schemaName, epoch);
|
|
5203
|
+
}
|
|
5204
|
+
/** True when the schema's instances were evicted after `since` (an epoch from currentEvictionEpoch). */
|
|
5205
|
+
function schemaEvictedSince(schemaName, since) {
|
|
5206
|
+
if (epoch === since || !schemaName)
|
|
5207
|
+
return false;
|
|
5208
|
+
return (lastEvictionBySchema.get(schemaName) ?? 0) > since;
|
|
5209
|
+
}
|
|
5210
|
+
/** True when any schema was evicted after `since` (cheap check before looking up which schemas apply). */
|
|
5211
|
+
function anyEvictionSince(since) {
|
|
5212
|
+
return epoch !== since;
|
|
5213
|
+
}
|
|
5214
|
+
|
|
5137
5215
|
const logger$t = debug('seedSdk:write:validateEntity');
|
|
5138
5216
|
// XState v5 type inference bug: fromPromise types are inverted
|
|
5139
5217
|
// We use type assertion to work around this
|
|
@@ -5141,6 +5219,18 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
5141
5219
|
// Type assertion to fix XState v5 type inference bug
|
|
5142
5220
|
// Convert through unknown to avoid type overlap error
|
|
5143
5221
|
const entityInput = input;
|
|
5222
|
+
// Validation awaits imports before looking up the schema; the entity can be evicted with its
|
|
5223
|
+
// schema meanwhile (Schema.destroy, test cleanup). Schema.create would then load the evicted
|
|
5224
|
+
// schema again, and its load re-creates the schema's models from rows being deleted.
|
|
5225
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
5226
|
+
/** The schema to validate against; throws (validation then skips the schema check) once it was evicted. */
|
|
5227
|
+
const schemaForValidation = async (schemaName) => {
|
|
5228
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-BXhXdUsA.js'); });
|
|
5229
|
+
if (schemaEvictedSince(schemaName, evictionEpoch)) {
|
|
5230
|
+
throw new Error(`Schema "${schemaName}" was evicted during validation`);
|
|
5231
|
+
}
|
|
5232
|
+
return Schema.create(schemaName, { waitForReady: false });
|
|
5233
|
+
};
|
|
5144
5234
|
const _validate = async () => {
|
|
5145
5235
|
try {
|
|
5146
5236
|
const msg = `[validateEntity] Starting validation for ${entityInput.entityType}`;
|
|
@@ -5151,7 +5241,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
5151
5241
|
const structureMsg = `[validateEntity] Validating model structure`;
|
|
5152
5242
|
logger$t(structureMsg);
|
|
5153
5243
|
// Use existing Model validation
|
|
5154
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
5244
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CC18QDfc.js'); });
|
|
5155
5245
|
const { SchemaValidationService } = validationServiceMod;
|
|
5156
5246
|
const validationService = new SchemaValidationService();
|
|
5157
5247
|
// Validate model structure
|
|
@@ -5169,11 +5259,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
5169
5259
|
if (entityInput.entityData.schemaName) {
|
|
5170
5260
|
try {
|
|
5171
5261
|
logger$t(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
|
|
5172
|
-
const
|
|
5173
|
-
const { Schema } = schemaMod;
|
|
5174
|
-
const schema = Schema.create(entityInput.entityData.schemaName, {
|
|
5175
|
-
waitForReady: false,
|
|
5176
|
-
});
|
|
5262
|
+
const schema = await schemaForValidation(entityInput.entityData.schemaName);
|
|
5177
5263
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
5178
5264
|
const schemaStatus = schemaSnapshot.value;
|
|
5179
5265
|
logger$t(`[validateEntity] Schema status: ${schemaStatus}`);
|
|
@@ -5205,7 +5291,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
5205
5291
|
}
|
|
5206
5292
|
else if (entityInput.entityType === 'modelProperty') {
|
|
5207
5293
|
// Use existing ModelProperty validation
|
|
5208
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
5294
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CC18QDfc.js'); });
|
|
5209
5295
|
const { SchemaValidationService } = validationServiceMod;
|
|
5210
5296
|
const validationService = new SchemaValidationService();
|
|
5211
5297
|
// Validate property structure
|
|
@@ -5220,11 +5306,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
5220
5306
|
// If schema name and model name provided, validate against schema
|
|
5221
5307
|
if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
|
|
5222
5308
|
try {
|
|
5223
|
-
const
|
|
5224
|
-
const { Schema } = schemaMod;
|
|
5225
|
-
const schema = Schema.create(entityInput.entityData._schemaName, {
|
|
5226
|
-
waitForReady: false,
|
|
5227
|
-
});
|
|
5309
|
+
const schema = await schemaForValidation(entityInput.entityData._schemaName);
|
|
5228
5310
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
5229
5311
|
const schemaStatus = schemaSnapshot.value;
|
|
5230
5312
|
if (schemaStatus === 'idle') {
|
|
@@ -5249,7 +5331,7 @@ const validateEntity = xstate.fromPromise(async ({ input }) => {
|
|
|
5249
5331
|
}
|
|
5250
5332
|
else if (entityInput.entityType === 'schema') {
|
|
5251
5333
|
// Schema validation - use existing validation
|
|
5252
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
5334
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-CC18QDfc.js'); });
|
|
5253
5335
|
const { SchemaValidationService } = validationServiceMod;
|
|
5254
5336
|
const validationService = new SchemaValidationService();
|
|
5255
5337
|
const schemaResult = validationService.validateSchema(entityInput.entityData);
|
|
@@ -5338,7 +5420,7 @@ const writeToDatabase = xstate.fromCallback(({ sendBack, input }) => {
|
|
|
5338
5420
|
// initial write completes is not overwritten by the stale requestWrite payload.
|
|
5339
5421
|
let dataToWrite = input.entityData;
|
|
5340
5422
|
try {
|
|
5341
|
-
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-
|
|
5423
|
+
const mod = await Promise.resolve().then(function () { return require('./ModelProperty-BT6Un_MB.js'); });
|
|
5342
5424
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
5343
5425
|
if (ModelProperty && typeof ModelProperty.getById === 'function') {
|
|
5344
5426
|
const instance = ModelProperty.getById(input.entityId);
|
|
@@ -5721,16 +5803,23 @@ const modelMachine = xstate.setup({
|
|
|
5721
5803
|
({ context, event, self }) => {
|
|
5722
5804
|
if (event._liveQueryPropertyIds !== undefined) {
|
|
5723
5805
|
const newPropertyIds = event._liveQueryPropertyIds;
|
|
5806
|
+
// The model can be evicted with its schema (Schema.destroy, test cleanup) before the
|
|
5807
|
+
// timer and import below run: then create nothing, and drop lookups an eviction overtakes.
|
|
5808
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
5724
5809
|
// Use setTimeout to check after assign has been applied
|
|
5725
5810
|
setTimeout(() => {
|
|
5726
|
-
self.getSnapshot();
|
|
5811
|
+
const snapshot = self.getSnapshot();
|
|
5812
|
+
if (snapshot.status === 'stopped')
|
|
5813
|
+
return;
|
|
5727
5814
|
// Create ModelProperty instances for any new property IDs
|
|
5728
5815
|
if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
|
|
5729
5816
|
// Import and create instances asynchronously (fire-and-forget)
|
|
5730
|
-
Promise.resolve().then(function () { return require('./ModelProperty-
|
|
5817
|
+
Promise.resolve().then(function () { return require('./ModelProperty-BT6Un_MB.js'); }).then(({ ModelProperty }) => {
|
|
5818
|
+
if (self.getSnapshot().status === 'stopped')
|
|
5819
|
+
return;
|
|
5731
5820
|
const createPromises = newPropertyIds.map(async (propertyFileId) => {
|
|
5732
5821
|
try {
|
|
5733
|
-
const property = await ModelProperty.createById(propertyFileId);
|
|
5822
|
+
const property = await ModelProperty.createById(propertyFileId, { evictionEpoch });
|
|
5734
5823
|
if (property) {
|
|
5735
5824
|
logger$q(`[modelMachine] Created/cached ModelProperty instance for propertyFileId "${propertyFileId}" after _liveQueryPropertyIds update`);
|
|
5736
5825
|
}
|
|
@@ -6455,7 +6544,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
6455
6544
|
const schemaNameToTry = schemaName ?? model$1?.schemaName;
|
|
6456
6545
|
if (schemaNameToTry) {
|
|
6457
6546
|
try {
|
|
6458
|
-
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-
|
|
6547
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-BXhXdUsA.js'); });
|
|
6459
6548
|
const schemaInstance = Schema.create(schemaNameToTry, { waitForReady: false });
|
|
6460
6549
|
const schemaContext = schemaInstance.getService().getSnapshot().context;
|
|
6461
6550
|
if (schemaContext.models?.[modelName]?.properties) {
|
|
@@ -6508,7 +6597,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
6508
6597
|
}
|
|
6509
6598
|
}
|
|
6510
6599
|
if (Object.keys(propertySchemas).length === 0) {
|
|
6511
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
6600
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
6512
6601
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
6513
6602
|
const KNOWN_MODEL_FALLBACKS = {
|
|
6514
6603
|
Post: {
|
|
@@ -6525,7 +6614,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
6525
6614
|
}
|
|
6526
6615
|
}
|
|
6527
6616
|
// Fallbacks above may return schema-file shape ({ type, model, items }); normalize to dataType/ref/refValueType.
|
|
6528
|
-
const { normalizePropertyRecordSchema } = await Promise.resolve().then(function () { return require('./property-
|
|
6617
|
+
const { normalizePropertyRecordSchema } = await Promise.resolve().then(function () { return require('./property-ZerTWizX.js'); });
|
|
6529
6618
|
propertySchemas = Object.fromEntries(Object.entries(propertySchemas).map(([name, def]) => [name, normalizePropertyRecordSchema(def)]));
|
|
6530
6619
|
// Collapse rows that map to the same instance key (e.g. authorIdentityIds + authors -> authors).
|
|
6531
6620
|
// ItemProperty.create cache does not sync propertyValue on hit; processing order would otherwise
|
|
@@ -6558,7 +6647,7 @@ const createItemPropertyInstances = async (metadataRows, seedLocalId, seedUid, m
|
|
|
6558
6647
|
// Infer propertyRecordSchema from metadata when schema is missing (enables persistence)
|
|
6559
6648
|
let propSchema = propertySchemas[propertyName];
|
|
6560
6649
|
if (!propSchema && isRefTypeFromMeta) {
|
|
6561
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
6650
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
6562
6651
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
6563
6652
|
propSchema = {
|
|
6564
6653
|
dataType: refSeedType === 'html' ? ModelPropertyDataTypes.Html
|
|
@@ -6825,14 +6914,23 @@ const runPublish = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
6825
6914
|
sendBack({ type: 'publishError', error: new Error(`Item not found for seedLocalId: ${seedLocalId}`) });
|
|
6826
6915
|
return;
|
|
6827
6916
|
}
|
|
6828
|
-
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-
|
|
6917
|
+
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-Bh22D3zJ.js'); });
|
|
6829
6918
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
6830
|
-
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-
|
|
6919
|
+
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DRJh7WR0.js'); });
|
|
6831
6920
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
6832
6921
|
const uploads = await getPublishUploads(item);
|
|
6833
6922
|
let uploadedTransactions = [];
|
|
6834
6923
|
const executor = getUploadExecutor();
|
|
6835
|
-
if (executor && uploads.length > 0)
|
|
6924
|
+
if (executor && uploads.length > 0) {
|
|
6925
|
+
for (const upload of uploads) {
|
|
6926
|
+
const { txId } = await executor(upload);
|
|
6927
|
+
uploadedTransactions.push({
|
|
6928
|
+
txId,
|
|
6929
|
+
seedLocalId: upload.seedLocalId,
|
|
6930
|
+
versionLocalId: upload.versionLocalId,
|
|
6931
|
+
});
|
|
6932
|
+
}
|
|
6933
|
+
}
|
|
6836
6934
|
await getPublishPayload(item, uploadedTransactions);
|
|
6837
6935
|
logger$o('runPublish: payload prepared (upload/EAS submit stubbed)');
|
|
6838
6936
|
sendBack({ type: 'publishSuccess' });
|
|
@@ -7576,6 +7674,29 @@ const getItemsData = async ({ modelName, modelFileId, schemaName, deleted, inclu
|
|
|
7576
7674
|
});
|
|
7577
7675
|
};
|
|
7578
7676
|
|
|
7677
|
+
/**
|
|
7678
|
+
* The seed's head version row: newest by (created_at DESC, local_id DESC), attested or not, skipping
|
|
7679
|
+
* revoked versions. Null when the seed has no version or every version is revoked (a fully
|
|
7680
|
+
* unpublished item). Same choice as `latestVersionLocalId` in the `getVersionData` subquery.
|
|
7681
|
+
*/
|
|
7682
|
+
async function getLatestVersionRow(seedLocalId) {
|
|
7683
|
+
const appDb = BaseDb.getAppDb();
|
|
7684
|
+
if (!appDb || !seedLocalId)
|
|
7685
|
+
return null;
|
|
7686
|
+
const rows = await appDb
|
|
7687
|
+
.select({
|
|
7688
|
+
localId: versions.localId,
|
|
7689
|
+
uid: versions.uid,
|
|
7690
|
+
createdAt: versions.createdAt,
|
|
7691
|
+
attestationCreatedAt: versions.attestationCreatedAt,
|
|
7692
|
+
})
|
|
7693
|
+
.from(versions)
|
|
7694
|
+
.where(drizzleOrm.and(drizzleOrm.eq(versions.seedLocalId, seedLocalId), versionNotRevoked()))
|
|
7695
|
+
.orderBy(drizzleOrm.desc(versions.createdAt), drizzleOrm.desc(versions.localId))
|
|
7696
|
+
.limit(1);
|
|
7697
|
+
return rows[0] ?? null;
|
|
7698
|
+
}
|
|
7699
|
+
|
|
7579
7700
|
const logger$m = debug('seedSdk:ItemProperty:service:actors:waitForDb');
|
|
7580
7701
|
const waitForDb = xstate.fromCallback(({ sendBack }) => {
|
|
7581
7702
|
// Check immediately first
|
|
@@ -7770,7 +7891,7 @@ const resolveRelatedValue = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
7770
7891
|
const { isRelation, propertyValue, propertyName, seedUid, propertyRecordSchema, populatedFromDb, schemaUid, } = context;
|
|
7771
7892
|
const _resolveRelatedValue = async () => {
|
|
7772
7893
|
// Use dynamic import to break circular dependency
|
|
7773
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
7894
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
7774
7895
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
7775
7896
|
if (!propertyValue || !isRelation || populatedFromDb) {
|
|
7776
7897
|
return;
|
|
@@ -8264,7 +8385,7 @@ const hydrateFromDb = xstate.fromCallback(({ sendBack, input: { context } }) =>
|
|
|
8264
8385
|
// to use dynamically imported ModelPropertyDataTypes
|
|
8265
8386
|
const _hydrateFromDb = async () => {
|
|
8266
8387
|
// Use dynamic import to break circular dependency
|
|
8267
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
8388
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
8268
8389
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
8269
8390
|
const appDb = BaseDb.getAppDb();
|
|
8270
8391
|
const whereClauses = [];
|
|
@@ -8641,7 +8762,7 @@ const loadOrCreateProperty = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
8641
8762
|
};
|
|
8642
8763
|
// Merge with schema from file/DB to get validation rules (enum, pattern, etc.) - properties table doesn't store these
|
|
8643
8764
|
try {
|
|
8644
|
-
const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-
|
|
8765
|
+
const { getPropertySchema } = await Promise.resolve().then(function () { return require('./property-ZerTWizX.js'); });
|
|
8645
8766
|
let schemaFromFile = await getPropertySchema(normalizedModelName, propertyName, {
|
|
8646
8767
|
modelFileId: modelRecord?.schemaFileId ?? modelFileId,
|
|
8647
8768
|
});
|
|
@@ -9062,9 +9183,9 @@ const analyzeInput = xstate.fromCallback(({ sendBack, input: { context, event }
|
|
|
9062
9183
|
}
|
|
9063
9184
|
const _analyzeInput = async () => {
|
|
9064
9185
|
// Use dynamic import to break circular dependency
|
|
9065
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
9186
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
9066
9187
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
9067
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
9188
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CC18QDfc.js'); });
|
|
9068
9189
|
let propertyName = propertyNameRaw;
|
|
9069
9190
|
if (!propertyName) {
|
|
9070
9191
|
throw new Error('propertyName is required');
|
|
@@ -9554,7 +9675,7 @@ const createMetadata = async (metadataValues, propertyRecordSchema, options) =>
|
|
|
9554
9675
|
propertyRecordSchema?.validation &&
|
|
9555
9676
|
metadataValues.propertyValue != null &&
|
|
9556
9677
|
metadataValues.propertyValue !== '') {
|
|
9557
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
9678
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CC18QDfc.js'); });
|
|
9558
9679
|
const validationService = new SchemaValidationService();
|
|
9559
9680
|
const validationResult = validationService.validatePropertyValue(metadataValues.propertyValue, normalizeDataType(propertyRecordSchema.dataType), propertyRecordSchema.validation, propertyRecordSchema.refValueType
|
|
9560
9681
|
? normalizeDataType(String(propertyRecordSchema.refValueType))
|
|
@@ -10136,7 +10257,7 @@ const saveRelation = xstate.fromCallback(({ sendBack, input: { context, event }
|
|
|
10136
10257
|
}
|
|
10137
10258
|
const _saveRelation = async () => {
|
|
10138
10259
|
// Use dynamic import to break circular dependency
|
|
10139
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
10260
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
10140
10261
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
10141
10262
|
if (!propertyNameRaw) {
|
|
10142
10263
|
throw new Error('propertyName is required');
|
|
@@ -11102,7 +11223,7 @@ class ItemProperty {
|
|
|
11102
11223
|
return;
|
|
11103
11224
|
}
|
|
11104
11225
|
// Use dynamic import to break circular dependency
|
|
11105
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
11226
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./index-BA1RIYFG.js'); });
|
|
11106
11227
|
const { ModelPropertyDataTypes } = schemaMod;
|
|
11107
11228
|
const { context } = snapshot;
|
|
11108
11229
|
const { propertyRecordSchema } = context;
|
|
@@ -11763,6 +11884,29 @@ class ItemProperty {
|
|
|
11763
11884
|
return result;
|
|
11764
11885
|
return waitForEntityIdle(result, { timeout: readyTimeout }).then(() => result);
|
|
11765
11886
|
}
|
|
11887
|
+
/**
|
|
11888
|
+
* The cached ItemProperty when it can be read right now (idle, not saving), the state
|
|
11889
|
+
* `ItemProperty.find()` waits for. Otherwise undefined. Unlike `find`, it takes no cache hold, so
|
|
11890
|
+
* React hooks can call it during render.
|
|
11891
|
+
*/
|
|
11892
|
+
static peekReady({ propertyName, seedLocalId, seedUid, }) {
|
|
11893
|
+
if (!propertyName)
|
|
11894
|
+
return undefined;
|
|
11895
|
+
// Same key order as find(), then the other id: instances are cached under both when both are known.
|
|
11896
|
+
const keys = [seedUid, seedLocalId]
|
|
11897
|
+
.filter((id) => typeof id === 'string' && id.length > 0)
|
|
11898
|
+
.map((id) => this.cacheKey(id, propertyName));
|
|
11899
|
+
for (const key of keys) {
|
|
11900
|
+
const instance = this.instanceCache.get(key)?.instance;
|
|
11901
|
+
if (!instance)
|
|
11902
|
+
continue;
|
|
11903
|
+
const snap = instance.getService().getSnapshot();
|
|
11904
|
+
if (snap.status !== 'active' || snap.value !== 'idle' || snap.context?.isSaving)
|
|
11905
|
+
return undefined;
|
|
11906
|
+
return instance;
|
|
11907
|
+
}
|
|
11908
|
+
return undefined;
|
|
11909
|
+
}
|
|
11766
11910
|
static async find({ propertyName, seedLocalId, seedUid, modelName: modelNameOption, waitForReady = true, readyTimeout = 5000, }) {
|
|
11767
11911
|
if ((!seedLocalId && !seedUid) || !propertyName) {
|
|
11768
11912
|
return undefined;
|
|
@@ -12478,7 +12622,6 @@ class Item {
|
|
|
12478
12622
|
const revokedAt = Math.floor(Date.now() / 1000);
|
|
12479
12623
|
// The executor stamps the revoked version rows; the latest version is now the newest one left
|
|
12480
12624
|
// (a local draft) or none, never a revoked one.
|
|
12481
|
-
const { getLatestVersionRow } = await Promise.resolve().then(function () { return require('./getLatestVersionRow-DVizNNoI.js'); });
|
|
12482
12625
|
const head = await getLatestVersionRow(this.seedLocalId);
|
|
12483
12626
|
this._service.send({
|
|
12484
12627
|
type: 'updateContext',
|
|
@@ -12524,12 +12667,12 @@ class Item {
|
|
|
12524
12667
|
};
|
|
12525
12668
|
this.getPublishUploads = async (options) => {
|
|
12526
12669
|
// Use dynamic import to break circular dependency
|
|
12527
|
-
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-
|
|
12670
|
+
const getPublishUploadsMod = await Promise.resolve().then(function () { return require('./getPublishUploads-Bh22D3zJ.js'); });
|
|
12528
12671
|
const { getPublishUploads } = getPublishUploadsMod;
|
|
12529
12672
|
return await getPublishUploads(this, [], undefined, options);
|
|
12530
12673
|
};
|
|
12531
12674
|
this.getPublishPayload = async (uploadedTransactions, options) => {
|
|
12532
|
-
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-
|
|
12675
|
+
const getPublishPayloadMod = await Promise.resolve().then(function () { return require('./getPublishPayload-DRJh7WR0.js'); });
|
|
12533
12676
|
const { getPublishPayload } = getPublishPayloadMod;
|
|
12534
12677
|
return await getPublishPayload(this, uploadedTransactions, options);
|
|
12535
12678
|
};
|
|
@@ -12546,7 +12689,6 @@ class Item {
|
|
|
12546
12689
|
});
|
|
12547
12690
|
// Publish has recorded the version it attested (updateVersionUid): reflect it here too, as
|
|
12548
12691
|
// the versions liveQuery does in the browser. After a republish this is the new version.
|
|
12549
|
-
const { getLatestVersionRow } = await Promise.resolve().then(function () { return require('./getLatestVersionRow-DVizNNoI.js'); });
|
|
12550
12692
|
const head = await getLatestVersionRow(seedLocalId);
|
|
12551
12693
|
if (head?.localId) {
|
|
12552
12694
|
this._service.send({
|
|
@@ -12802,6 +12944,38 @@ class Item {
|
|
|
12802
12944
|
}
|
|
12803
12945
|
}
|
|
12804
12946
|
}
|
|
12947
|
+
/**
|
|
12948
|
+
* Idle, and not the shell the item machine can be in when it reaches `idle` before
|
|
12949
|
+
* `propertyInstances` is merged (an item with a version but no property instances yet).
|
|
12950
|
+
*/
|
|
12951
|
+
static isItemSnapshotReadyForRead(snap) {
|
|
12952
|
+
if (!snap || !('value' in snap) || snap.value !== 'idle') {
|
|
12953
|
+
return false;
|
|
12954
|
+
}
|
|
12955
|
+
const ctx = snap.context || {};
|
|
12956
|
+
const versionsCount = ctx.versionsCount ?? 0;
|
|
12957
|
+
const hasHeadVersion = !!ctx.latestVersionLocalId;
|
|
12958
|
+
if (versionsCount === 0 && !hasHeadVersion) {
|
|
12959
|
+
return true;
|
|
12960
|
+
}
|
|
12961
|
+
return (ctx.propertyInstances?.size ?? 0) > 0;
|
|
12962
|
+
}
|
|
12963
|
+
/**
|
|
12964
|
+
* The cached Item for a seedLocalId or seedUid when it can be read right now: idle and hydrated,
|
|
12965
|
+
* so at least what `Item.find()` would wait for. Otherwise undefined. Unlike `getById`, it takes
|
|
12966
|
+
* no cache hold, so React hooks can call it during render.
|
|
12967
|
+
*/
|
|
12968
|
+
static peekReady(id) {
|
|
12969
|
+
if (!id)
|
|
12970
|
+
return undefined;
|
|
12971
|
+
const instance = this.findItemInstanceCacheEntryById(id)?.instance;
|
|
12972
|
+
if (!instance)
|
|
12973
|
+
return undefined;
|
|
12974
|
+
const snap = instance.getService().getSnapshot();
|
|
12975
|
+
if (snap.status !== 'active')
|
|
12976
|
+
return undefined;
|
|
12977
|
+
return this.isItemSnapshotReadyForRead(snap) ? instance : undefined;
|
|
12978
|
+
}
|
|
12805
12979
|
/**
|
|
12806
12980
|
* Item machine can reach `idle` before `propertyInstances` is merged (race) or while
|
|
12807
12981
|
* child ItemProperty actors are still hydrating. useItems / Item.all must not return that shell.
|
|
@@ -12814,16 +12988,7 @@ class Item {
|
|
|
12814
12988
|
if ('value' in snap && snap.value === 'error') {
|
|
12815
12989
|
throw new Error('Entity failed to load');
|
|
12816
12990
|
}
|
|
12817
|
-
|
|
12818
|
-
return false;
|
|
12819
|
-
}
|
|
12820
|
-
const ctx = snap.context || {};
|
|
12821
|
-
const versionsCount = ctx.versionsCount ?? 0;
|
|
12822
|
-
const hasHeadVersion = !!ctx.latestVersionLocalId;
|
|
12823
|
-
if (versionsCount === 0 && !hasHeadVersion) {
|
|
12824
|
-
return true;
|
|
12825
|
-
}
|
|
12826
|
-
return (ctx.propertyInstances?.size ?? 0) > 0;
|
|
12991
|
+
return Item.isItemSnapshotReadyForRead(snap);
|
|
12827
12992
|
}, { timeout: readyTimeout });
|
|
12828
12993
|
}
|
|
12829
12994
|
catch (e) {
|
|
@@ -14313,7 +14478,7 @@ const runEasSync = xstate.fromPromise(async ({ input, }) => {
|
|
|
14313
14478
|
requestPayload: input.requestPayload,
|
|
14314
14479
|
persistedSnapshot: input.runningSnapshot,
|
|
14315
14480
|
});
|
|
14316
|
-
const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-
|
|
14481
|
+
const { runSyncFromEas } = await Promise.resolve().then(function () { return require('./syncDbWithEas-CYfPkus9.js'); });
|
|
14317
14482
|
try {
|
|
14318
14483
|
// Sync checks for rows and then inserts the rest (no unique index on uids), so syncs in
|
|
14319
14484
|
// different tabs take turns. A sync can run for minutes, so wait without a timeout.
|
|
@@ -18388,7 +18553,9 @@ async function listPublishedSeedRows(schemaName, opts) {
|
|
|
18388
18553
|
markedForDeletion: seeds._markedForDeletion,
|
|
18389
18554
|
})
|
|
18390
18555
|
.from(seeds)
|
|
18391
|
-
.where(drizzleOrm.and(drizzleOrm.inArray(seeds.type, typeCandidates), drizzleOrm.isNotNull(seeds.uid),
|
|
18556
|
+
.where(drizzleOrm.and(drizzleOrm.inArray(seeds.type, typeCandidates), drizzleOrm.isNotNull(seeds.uid),
|
|
18557
|
+
// The query layer passes `0x` + hex only, so no LIKE wildcards to escape.
|
|
18558
|
+
opts?.uidPrefix ? drizzleOrm.like(seeds.uid, `${opts.uidPrefix}%`) : undefined, drizzleOrm.or(drizzleOrm.isNull(seeds.revokedAt), drizzleOrm.eq(seeds.revokedAt, 0)), drizzleOrm.or(drizzleOrm.isNull(seeds._markedForDeletion), drizzleOrm.eq(seeds._markedForDeletion, 0))))
|
|
18392
18559
|
.orderBy(drizzleOrm.desc(seeds.attestationCreatedAt));
|
|
18393
18560
|
const out = [];
|
|
18394
18561
|
for (const row of rows) {
|
|
@@ -18467,6 +18634,10 @@ function createLocalQueryDataSource() {
|
|
|
18467
18634
|
const all = await listPublishedSeedRows(schemaName);
|
|
18468
18635
|
return all.slice(opts.skip, opts.skip + opts.limit);
|
|
18469
18636
|
},
|
|
18637
|
+
async listSeedsByUidPrefix(schemaName, uidPrefix, opts) {
|
|
18638
|
+
const matching = await listPublishedSeedRows(schemaName, { uidPrefix });
|
|
18639
|
+
return matching.slice(opts.skip, opts.skip + opts.limit);
|
|
18640
|
+
},
|
|
18470
18641
|
async listSeedsBySchemaNameForMonth(schemaName, year, month) {
|
|
18471
18642
|
const { startTs, endTs } = monthBoundsUnix(year, month);
|
|
18472
18643
|
return listPublishedSeedRows(schemaName, { startTs, endTs });
|
|
@@ -18976,22 +19147,6 @@ var ClientManager$1 = /*#__PURE__*/Object.freeze({
|
|
|
18976
19147
|
getClient: getClient
|
|
18977
19148
|
});
|
|
18978
19149
|
|
|
18979
|
-
/**
|
|
18980
|
-
* Common getters and utilities for entity classes
|
|
18981
|
-
* These work with any entity that has a getService() method returning an XState actor
|
|
18982
|
-
*/
|
|
18983
|
-
/**
|
|
18984
|
-
* Get the current state value from an entity's service
|
|
18985
|
-
*/
|
|
18986
|
-
/**
|
|
18987
|
-
* Whether an actor has been stopped (unload, destroy, or Schema eviction). Async work started by an
|
|
18988
|
-
* entity (DB lookups, retry timers) must check this before sending, since a stopped actor ignores
|
|
18989
|
-
* events and XState warns about every one of them.
|
|
18990
|
-
*/
|
|
18991
|
-
function isActorStopped(actor) {
|
|
18992
|
-
return actor.getSnapshot().status === 'stopped';
|
|
18993
|
-
}
|
|
18994
|
-
|
|
18995
19150
|
/**
|
|
18996
19151
|
* Set up liveQuery subscription for an entity
|
|
18997
19152
|
* This enables cross-instance synchronization (e.g., changes in other tabs/windows)
|
|
@@ -19017,7 +19172,10 @@ function setupEntityLiveQuery(instance, config) {
|
|
|
19017
19172
|
const initialIds = config.extractEntityIds(initialRows);
|
|
19018
19173
|
if (initialIds.length > 0) {
|
|
19019
19174
|
logger(`Initial query returned ${initialIds.length} entities`);
|
|
19020
|
-
// Create child instances if provided
|
|
19175
|
+
// Create child instances if provided (not for a stopped entity: an unloaded or evicted
|
|
19176
|
+
// parent must not re-cache its children)
|
|
19177
|
+
if (isActorStopped(instance.getService()))
|
|
19178
|
+
return;
|
|
19021
19179
|
if (config.createChildInstances) {
|
|
19022
19180
|
await config.createChildInstances(initialIds);
|
|
19023
19181
|
}
|
|
@@ -19048,7 +19206,9 @@ function setupEntityLiveQuery(instance, config) {
|
|
|
19048
19206
|
}
|
|
19049
19207
|
logger(`Query returned ${rows.length} rows`);
|
|
19050
19208
|
const ids = config.extractEntityIds(rows);
|
|
19051
|
-
// Create child instances if provided (before updating context)
|
|
19209
|
+
// Create child instances if provided (before updating context; not for a stopped entity)
|
|
19210
|
+
if (isActorStopped(instance.getService()))
|
|
19211
|
+
return;
|
|
19052
19212
|
if (config.createChildInstances && ids.length > 0) {
|
|
19053
19213
|
await config.createChildInstances(ids);
|
|
19054
19214
|
}
|
|
@@ -19189,7 +19349,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
|
|
|
19189
19349
|
// Lazy import cache for ModelProperty to avoid circular dependency
|
|
19190
19350
|
// Eagerly start loading to minimize delay on first access
|
|
19191
19351
|
let ModelPropertyClass = null;
|
|
19192
|
-
const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-
|
|
19352
|
+
const modelPropertyImportPromise = Promise.resolve().then(function () { return require('./ModelProperty-BT6Un_MB.js'); })
|
|
19193
19353
|
.then(module => {
|
|
19194
19354
|
ModelPropertyClass = module.ModelProperty;
|
|
19195
19355
|
return ModelPropertyClass;
|
|
@@ -19205,7 +19365,7 @@ function getModelProperty() {
|
|
|
19205
19365
|
return ModelPropertyClass;
|
|
19206
19366
|
}
|
|
19207
19367
|
// Lazy import for Schema to avoid circular dependency
|
|
19208
|
-
const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-
|
|
19368
|
+
const schemaImportPromise = Promise.resolve().then(function () { return require('./Schema-BXhXdUsA.js'); })
|
|
19209
19369
|
.then(module => module.Schema)
|
|
19210
19370
|
.catch(() => null);
|
|
19211
19371
|
// WeakMap to store mutable state per Model instance
|
|
@@ -19703,6 +19863,9 @@ class Model {
|
|
|
19703
19863
|
resolve();
|
|
19704
19864
|
}, 10000);
|
|
19705
19865
|
});
|
|
19866
|
+
// Unloaded or evicted (e.g. Schema.destroy) while it loaded: a stopped model never writes
|
|
19867
|
+
if (isActorStopped(proxiedInstance._service))
|
|
19868
|
+
return;
|
|
19706
19869
|
// Only write if validation passed (model is in idle state, not error)
|
|
19707
19870
|
const finalSnapshot = proxiedInstance._service.getSnapshot();
|
|
19708
19871
|
if (finalSnapshot.value === 'idle' && (!finalSnapshot.context._validationErrors || finalSnapshot.context._validationErrors.length === 0)) {
|
|
@@ -19826,8 +19989,8 @@ class Model {
|
|
|
19826
19989
|
}
|
|
19827
19990
|
logger$2(`WARNING: Could not verify schema exists in database: ${error}. Proceeding anyway.`);
|
|
19828
19991
|
}
|
|
19829
|
-
|
|
19830
|
-
|
|
19992
|
+
const pendingModelFileId = finalSnapshot.context.id;
|
|
19993
|
+
const pendingSchemaId = schemaId;
|
|
19831
19994
|
// Wait for writeProcess to be spawned (it's spawned in idle state entry action)
|
|
19832
19995
|
// Retry a few times if writeProcess isn't available yet
|
|
19833
19996
|
let retries = 0;
|
|
@@ -19838,6 +20001,8 @@ class Model {
|
|
|
19838
20001
|
return;
|
|
19839
20002
|
const currentSnapshot = proxiedInstance._service.getSnapshot();
|
|
19840
20003
|
if (currentSnapshot.context.writeProcess) {
|
|
20004
|
+
// Track pending write (only once it really starts: a stopped model leaves none behind)
|
|
20005
|
+
Model.trackPendingWrite(pendingModelFileId, pendingSchemaId); // id is now the schemaFileId (string)
|
|
19841
20006
|
logger$2(`Triggering write process for model "${finalSnapshot.context.modelName}" (schemaId: ${schemaId})`);
|
|
19842
20007
|
// Use pending property definitions if available, otherwise convert from ModelProperty instances
|
|
19843
20008
|
let propertiesObject = {};
|
|
@@ -20058,6 +20223,7 @@ class Model {
|
|
|
20058
20223
|
if (scope.modelFileId || scope.schemaName) {
|
|
20059
20224
|
const db = BaseDb.getAppDb();
|
|
20060
20225
|
if (db) {
|
|
20226
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
20061
20227
|
try {
|
|
20062
20228
|
const rows = await db
|
|
20063
20229
|
.select({
|
|
@@ -20074,6 +20240,9 @@ class Model {
|
|
|
20074
20240
|
.limit(1);
|
|
20075
20241
|
const record = rows[0];
|
|
20076
20242
|
if (record?.modelName && record.schemaName && record.modelFileId) {
|
|
20243
|
+
// Its schema was evicted while we read the row: don't bring the model back.
|
|
20244
|
+
if (schemaEvictedSince(record.schemaName, evictionEpoch))
|
|
20245
|
+
return undefined;
|
|
20077
20246
|
return this.create(record.modelName, record.schemaName, { id: record.modelFileId });
|
|
20078
20247
|
}
|
|
20079
20248
|
}
|
|
@@ -20092,7 +20261,7 @@ class Model {
|
|
|
20092
20261
|
* @param schemaName - Optional schema name (will query DB if not provided)
|
|
20093
20262
|
* @returns The Model instance if found, undefined otherwise
|
|
20094
20263
|
*/
|
|
20095
|
-
static async getByNameAsync(modelName, schemaName) {
|
|
20264
|
+
static async getByNameAsync(modelName, schemaName, options) {
|
|
20096
20265
|
// First try cache
|
|
20097
20266
|
const cached = this.getByName(modelName, schemaName);
|
|
20098
20267
|
if (cached) {
|
|
@@ -20104,6 +20273,7 @@ class Model {
|
|
|
20104
20273
|
if (!db) {
|
|
20105
20274
|
return undefined;
|
|
20106
20275
|
}
|
|
20276
|
+
const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
|
|
20107
20277
|
try {
|
|
20108
20278
|
// Query model by name (throws AmbiguousModelError when several schemas define it)
|
|
20109
20279
|
const { resolveModelRecord } = await Promise.resolve().then(function () { return resolveModelRecord$1; });
|
|
@@ -20129,6 +20299,10 @@ class Model {
|
|
|
20129
20299
|
if (!record.modelName || !record.schemaName || !record.modelFileId) {
|
|
20130
20300
|
return undefined;
|
|
20131
20301
|
}
|
|
20302
|
+
// Its schema was evicted while we read the row: don't bring the model back.
|
|
20303
|
+
if (schemaEvictedSince(record.schemaName, evictionEpoch)) {
|
|
20304
|
+
return undefined;
|
|
20305
|
+
}
|
|
20132
20306
|
// Create model instance (will be cached)
|
|
20133
20307
|
return this.create(record.modelName, record.schemaName, {
|
|
20134
20308
|
id: record.modelFileId, // id is now the schemaFileId (string)
|
|
@@ -20150,7 +20324,7 @@ class Model {
|
|
|
20150
20324
|
* @param modelFileId - The model file ID to look up
|
|
20151
20325
|
* @returns The Model instance if found, undefined otherwise
|
|
20152
20326
|
*/
|
|
20153
|
-
static async createById(modelFileId) {
|
|
20327
|
+
static async createById(modelFileId, options) {
|
|
20154
20328
|
if (!modelFileId) {
|
|
20155
20329
|
return undefined;
|
|
20156
20330
|
}
|
|
@@ -20166,6 +20340,7 @@ class Model {
|
|
|
20166
20340
|
logger$2(`Model.createById: Database not available for ID "${modelFileId}"`);
|
|
20167
20341
|
return undefined;
|
|
20168
20342
|
}
|
|
20343
|
+
const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
|
|
20169
20344
|
try {
|
|
20170
20345
|
// Query model by schemaFileId and join to get schema name
|
|
20171
20346
|
const modelRecords = await db
|
|
@@ -20188,6 +20363,12 @@ class Model {
|
|
|
20188
20363
|
logger$2(`Model.createById: Missing modelName or schemaName for ID "${modelFileId}"`);
|
|
20189
20364
|
return undefined;
|
|
20190
20365
|
}
|
|
20366
|
+
// Its schema was evicted while we read the row (e.g. a Schema live query in flight during
|
|
20367
|
+
// Schema.destroy or test cleanup): don't bring the model back.
|
|
20368
|
+
if (schemaEvictedSince(schemaName, evictionEpoch)) {
|
|
20369
|
+
logger$2(`Model.createById: schema "${schemaName}" was evicted during the lookup of "${modelFileId}"`);
|
|
20370
|
+
return undefined;
|
|
20371
|
+
}
|
|
20191
20372
|
// Step 3: Create model using existing create method (which will handle caching)
|
|
20192
20373
|
logger$2(`Model.createById: Creating model "${modelName}" in schema "${schemaName}" from ID "${modelFileId}"`);
|
|
20193
20374
|
return this.create(modelName, schemaName, {
|
|
@@ -20242,6 +20423,7 @@ class Model {
|
|
|
20242
20423
|
logger$2(`Model.createBySchemaId: Database not available for schema "${schemaIdentifier}"`);
|
|
20243
20424
|
return [];
|
|
20244
20425
|
}
|
|
20426
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
20245
20427
|
try {
|
|
20246
20428
|
// Query all models for this schema - support both schemaFileId and schema name
|
|
20247
20429
|
const modelRecords = await db
|
|
@@ -20264,6 +20446,10 @@ class Model {
|
|
|
20264
20446
|
if (!record.modelName || !record.schemaName || !record.modelFileId) {
|
|
20265
20447
|
continue;
|
|
20266
20448
|
}
|
|
20449
|
+
// Its schema was evicted while we read the rows: don't bring its models back.
|
|
20450
|
+
if (schemaEvictedSince(record.schemaName, evictionEpoch)) {
|
|
20451
|
+
continue;
|
|
20452
|
+
}
|
|
20267
20453
|
// Check cache first
|
|
20268
20454
|
const cached = this.getById(record.modelFileId);
|
|
20269
20455
|
if (cached) {
|
|
@@ -20710,6 +20896,8 @@ class Model {
|
|
|
20710
20896
|
* @returns names of the evicted models (so callers can evict their ModelProperty instances)
|
|
20711
20897
|
*/
|
|
20712
20898
|
static evictForSchema(schemaName) {
|
|
20899
|
+
// Work already running for this schema's models must not re-cache them when it finishes.
|
|
20900
|
+
recordSchemaEviction(schemaName);
|
|
20713
20901
|
const instances = new Set();
|
|
20714
20902
|
for (const { instance } of this.instanceCacheById.values())
|
|
20715
20903
|
instances.add(instance);
|
|
@@ -21242,7 +21430,7 @@ function resolveSdkDrizzleMigrationsDir(sdkRootDir) {
|
|
|
21242
21430
|
})();
|
|
21243
21431
|
// Also resolve relative to this module so temp-cwd tests / odd roots still find
|
|
21244
21432
|
// packages/sdk/src/db/drizzle (or dist/db/drizzle after publish).
|
|
21245
|
-
const moduleDir = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-
|
|
21433
|
+
const moduleDir = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cjs/index-Dls7aMjr.js', document.baseURI).href))));
|
|
21246
21434
|
const candidates = [
|
|
21247
21435
|
path.join(root, 'db', 'drizzle'), // production: sdkRoot is dist/
|
|
21248
21436
|
path.join(root, 'dist', 'db', 'drizzle'), // sdk package root with built dist
|
|
@@ -21312,10 +21500,10 @@ class NodeDb {
|
|
|
21312
21500
|
logger$1('[Db.prepareDb] running migrations from %s', outDir);
|
|
21313
21501
|
await migrator.migrate(db, { migrationsFolder: outDir });
|
|
21314
21502
|
this.db = db;
|
|
21315
|
-
const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-
|
|
21503
|
+
const { backfillMetadataPropertyIds } = await Promise.resolve().then(function () { return require('./backfillMetadataPropertyIds-DEHC9ejq.js'); });
|
|
21316
21504
|
await backfillMetadataPropertyIds();
|
|
21317
21505
|
// One-time: clear item data whose model can't be determined (seeds.model_file_id, migration 0015)
|
|
21318
|
-
const { resetAmbiguousLegacyItemData } = await Promise.resolve().then(function () { return require('./resetAmbiguousLegacyItemData-
|
|
21506
|
+
const { resetAmbiguousLegacyItemData } = await Promise.resolve().then(function () { return require('./resetAmbiguousLegacyItemData-adDl4LcT.js'); });
|
|
21319
21507
|
await resetAmbiguousLegacyItemData();
|
|
21320
21508
|
return this.db;
|
|
21321
21509
|
}
|
|
@@ -21842,6 +22030,7 @@ exports.VERSION_SCHEMA_UID = VERSION_SCHEMA_UID;
|
|
|
21842
22030
|
exports.ZERO_BYTES32 = ZERO_BYTES32;
|
|
21843
22031
|
exports.addModelsToDb = addModelsToDb$1;
|
|
21844
22032
|
exports.addSchemaToDb = addSchemaToDb;
|
|
22033
|
+
exports.anyEvictionSince = anyEvictionSince;
|
|
21845
22034
|
exports.appState = appState;
|
|
21846
22035
|
exports.arweaveL1FinalizeJobs = arweaveL1FinalizeJobs;
|
|
21847
22036
|
exports.assertLocalDbChain = assertLocalDbChain;
|
|
@@ -21851,6 +22040,7 @@ exports.commandExists = commandExists;
|
|
|
21851
22040
|
exports.config = config;
|
|
21852
22041
|
exports.createModelsFromJson = createModelsFromJson;
|
|
21853
22042
|
exports.createReactiveProxy = createReactiveProxy;
|
|
22043
|
+
exports.currentEvictionEpoch = currentEvictionEpoch;
|
|
21854
22044
|
exports.db = db;
|
|
21855
22045
|
exports.defaultAttestationData = defaultAttestationData;
|
|
21856
22046
|
exports.easSyncProcesses = easSyncProcesses;
|
|
@@ -21866,6 +22056,7 @@ exports.getClient = getClient;
|
|
|
21866
22056
|
exports.getContentHash = getContentHash;
|
|
21867
22057
|
exports.getCorrectId = getCorrectId;
|
|
21868
22058
|
exports.getEasSchemaUidForModel = getEasSchemaUidForModel;
|
|
22059
|
+
exports.getGetAdditionalSyncAddresses = getGetAdditionalSyncAddresses;
|
|
21869
22060
|
exports.getItemData = getItemData;
|
|
21870
22061
|
exports.getItemModelScope = getItemModelScope;
|
|
21871
22062
|
exports.getItemStoragePropertiesForModel = getItemStoragePropertiesForModel;
|
|
@@ -21918,6 +22109,7 @@ exports.saveModelsFromMarkdown = saveModelsFromMarkdown;
|
|
|
21918
22109
|
exports.scheduleBulkFilesDownloadFromEasSync = scheduleBulkFilesDownloadFromEasSync;
|
|
21919
22110
|
exports.schema = schema$1;
|
|
21920
22111
|
exports.schema$1 = schema;
|
|
22112
|
+
exports.schemaEvictedSince = schemaEvictedSince;
|
|
21921
22113
|
exports.schemas = schemas;
|
|
21922
22114
|
exports.seeds = seeds;
|
|
21923
22115
|
exports.selectInBatches = selectInBatches;
|
|
@@ -21927,7 +22119,6 @@ exports.toSnakeCase = toSnakeCase;
|
|
|
21927
22119
|
exports.transformImportToSchemaFile = transformImportToSchemaFile;
|
|
21928
22120
|
exports.unloadEntity = unloadEntity;
|
|
21929
22121
|
exports.uploadProcesses = uploadProcesses;
|
|
21930
|
-
exports.versionNotRevoked = versionNotRevoked;
|
|
21931
22122
|
exports.versions = versions;
|
|
21932
22123
|
exports.waitForEasReadChain = waitForEasReadChain;
|
|
21933
22124
|
exports.waitForEntityIdle = waitForEntityIdle;
|
|
@@ -21935,4 +22126,4 @@ exports.withSeed = withSeed;
|
|
|
21935
22126
|
exports.writeInBatches = writeInBatches;
|
|
21936
22127
|
exports.writeProcessMachine = writeProcessMachine;
|
|
21937
22128
|
exports.writeToDatabase = writeToDatabase$1;
|
|
21938
|
-
//# sourceMappingURL=index-
|
|
22129
|
+
//# sourceMappingURL=index-Dls7aMjr.js.map
|