@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
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import { fromCallback, fromPromise, setup, assign, createActor } from 'xstate';
|
|
2
|
-
import {
|
|
2
|
+
import { a as BaseDb, j as models, p as properties, K as isInternalSchema, g as modelSchemas, s as schemas } from './BasePathResolver-BdxCSIzn.js';
|
|
3
3
|
import { eq, and, isNull, or } from 'drizzle-orm';
|
|
4
|
-
import './tabEvents-
|
|
4
|
+
import { b as generateId } from './tabEvents-C9qUKx_z.js';
|
|
5
5
|
import debug from 'debug';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { h as getClient } from './ClientManager-DLleL_2e.js';
|
|
6
|
+
import { G as writeModelToDb, K as writePropertyToDb, O as addSchemaToDb, A as AmbiguousModelError, Q as renameModelInDb, d as TProperty } from './db-W1g29qsM.js';
|
|
7
|
+
import { j as waitForEntityIdle, S as getInvariantSafePropertyDescriptor, m as findEntity, C as ClientManagerState, I as Item, T as clearDestroySubscriptions, n as forceRemoveFromCaches, U as unloadEntity, o as runDestroyLifecycle } from './Item-B9Y4VuK1.js';
|
|
8
|
+
import { h as getClient } from './ClientManager-ClCwwhwo.js';
|
|
10
9
|
import { modelPropertiesToObject } from './model-DGMe-TTm.js';
|
|
11
10
|
import { toSnakeCase } from 'drizzle-orm/casing';
|
|
12
11
|
import { Type } from '@sinclair/typebox';
|
|
13
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Common getters and utilities for entity classes
|
|
15
|
+
* These work with any entity that has a getService() method returning an XState actor
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Get the current state value from an entity's service
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Whether an actor has been stopped (unload, destroy, or Schema eviction). Async work started by an
|
|
22
|
+
* entity (DB lookups, retry timers) must check this before sending, since a stopped actor ignores
|
|
23
|
+
* events and XState warns about every one of them.
|
|
24
|
+
*/
|
|
25
|
+
function isActorStopped(actor) {
|
|
26
|
+
return actor.getSnapshot().status === 'stopped';
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
const logger$7 = debug('seedSdk:model:actors:loadOrCreateModel');
|
|
15
30
|
/**
|
|
16
31
|
* Create ModelProperty instances for all property IDs to ensure they're cached
|
|
@@ -22,7 +37,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
22
37
|
return;
|
|
23
38
|
}
|
|
24
39
|
try {
|
|
25
|
-
const mod = await import('./ModelProperty-
|
|
40
|
+
const mod = await import('./ModelProperty-BMePcicQ.js');
|
|
26
41
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
27
42
|
if (!ModelProperty) {
|
|
28
43
|
logger$7('createPropertyInstances: ModelProperty not available from dynamic import');
|
|
@@ -53,7 +68,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
53
68
|
// Don't throw - this is best-effort to pre-populate cache
|
|
54
69
|
}
|
|
55
70
|
};
|
|
56
|
-
const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
71
|
+
const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
57
72
|
const _loadOrCreateModel = async () => {
|
|
58
73
|
const { modelName, schemaName, id, _idFromSchema } = context; // id is now the schemaFileId (string)
|
|
59
74
|
if (!modelName || !schemaName) {
|
|
@@ -88,10 +103,10 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
88
103
|
if (!modelRecord) {
|
|
89
104
|
// Model names are only unique per schema: prefer this schema's row, and otherwise only
|
|
90
105
|
// consider same-name rows that no schema claims yet (never another schema's model).
|
|
91
|
-
const _mod_0 = await import('./BasePathResolver-
|
|
106
|
+
const _mod_0 = await import('./BasePathResolver-BdxCSIzn.js');
|
|
92
107
|
const _ns_0 = _mod_0.R;
|
|
93
108
|
const { modelSchemas } = _ns_0;
|
|
94
|
-
const _mod_1 = await import('./BasePathResolver-
|
|
109
|
+
const _mod_1 = await import('./BasePathResolver-BdxCSIzn.js');
|
|
95
110
|
const _ns_1 = _mod_1.Q;
|
|
96
111
|
const { schemas: schemasTable } = _ns_1;
|
|
97
112
|
let dbModels = await db
|
|
@@ -196,7 +211,9 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
196
211
|
.map((record) => record.schemaFileId)
|
|
197
212
|
.filter((id) => id !== null && id !== undefined);
|
|
198
213
|
if (propertyFileIds.length > 0) {
|
|
199
|
-
|
|
214
|
+
// Not for a model stopped meanwhile (unloaded, or evicted with its schema)
|
|
215
|
+
if (!isActorStopped(self))
|
|
216
|
+
await createPropertyInstances(propertyFileIds);
|
|
200
217
|
}
|
|
201
218
|
// Generate schemaFileId if not set
|
|
202
219
|
if (!schemaFileId) {
|
|
@@ -237,10 +254,13 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
237
254
|
// Step 2: Fallback to Schema context (only if database doesn't have the model)
|
|
238
255
|
// This handles the case where model exists in schema file but not yet in database
|
|
239
256
|
try {
|
|
240
|
-
const _mod_2 = await import('./Schema-
|
|
257
|
+
const _mod_2 = await import('./Schema-COsEXXaR.js');
|
|
241
258
|
const _ns_2 = _mod_2.b;
|
|
242
259
|
const schemaMod = _ns_2;
|
|
243
260
|
const { Schema } = schemaMod;
|
|
261
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
262
|
+
if (isActorStopped(self))
|
|
263
|
+
return;
|
|
244
264
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
245
265
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
246
266
|
// Wait for schema to load if it's still loading
|
|
@@ -385,11 +405,11 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
385
405
|
}
|
|
386
406
|
// Also check database for models (in case they're persisted but not in Schema context)
|
|
387
407
|
if (db) {
|
|
388
|
-
const _mod_3 = await import('./BasePathResolver-
|
|
408
|
+
const _mod_3 = await import('./BasePathResolver-BdxCSIzn.js');
|
|
389
409
|
const _ns_3 = _mod_3.R;
|
|
390
410
|
const modelSchemaSchemaMod = _ns_3;
|
|
391
411
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
392
|
-
const _mod_4 = await import('./BasePathResolver-
|
|
412
|
+
const _mod_4 = await import('./BasePathResolver-BdxCSIzn.js');
|
|
393
413
|
const _ns_4 = _mod_4.Q;
|
|
394
414
|
const schemaSchemaMod = _ns_4;
|
|
395
415
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
@@ -485,12 +505,14 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
485
505
|
}
|
|
486
506
|
// Mark schema as draft when a new model is created so saveNewVersion() can persist it
|
|
487
507
|
try {
|
|
488
|
-
const _mod_5 = await import('./Schema-
|
|
508
|
+
const _mod_5 = await import('./Schema-COsEXXaR.js');
|
|
489
509
|
const _ns_5 = _mod_5.b;
|
|
490
510
|
const schemaMod = _ns_5;
|
|
491
511
|
const { Schema } = schemaMod;
|
|
492
|
-
|
|
493
|
-
|
|
512
|
+
if (!isActorStopped(self)) {
|
|
513
|
+
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
514
|
+
schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
|
|
515
|
+
}
|
|
494
516
|
}
|
|
495
517
|
catch (err) {
|
|
496
518
|
logger$7(`Failed to mark schema as draft after creating model: ${err}`);
|
|
@@ -511,7 +533,7 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
511
533
|
const logger$6 = debug('seedSdk:model:actors:validateModel');
|
|
512
534
|
// Validation timeout in milliseconds (10 seconds)
|
|
513
535
|
const VALIDATION_TIMEOUT_MS = 10000;
|
|
514
|
-
const validateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
536
|
+
const validateModel = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
515
537
|
let hasResponded = false;
|
|
516
538
|
// Timeout handler to ensure we always respond
|
|
517
539
|
const timeoutId = setTimeout(() => {
|
|
@@ -531,10 +553,10 @@ const validateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
531
553
|
const _validateModel = async () => {
|
|
532
554
|
try {
|
|
533
555
|
// Use dynamic imports to break circular dependencies
|
|
534
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
556
|
+
const validationServiceMod = await import('./SchemaValidationService-DabGMzSE.js');
|
|
535
557
|
const { SchemaValidationService } = validationServiceMod;
|
|
536
558
|
const validationService = new SchemaValidationService();
|
|
537
|
-
const _mod_6 = await import('./Schema-
|
|
559
|
+
const _mod_6 = await import('./Schema-COsEXXaR.js');
|
|
538
560
|
const _ns_6 = _mod_6.b;
|
|
539
561
|
const schemaMod = _ns_6;
|
|
540
562
|
const { Schema } = schemaMod;
|
|
@@ -551,6 +573,9 @@ const validateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
551
573
|
// If we have schema name, validate against schema
|
|
552
574
|
// CRITICAL: Use validateModelAgainstSchema which doesn't require the model to be in schema context
|
|
553
575
|
// This allows validation BEFORE registration, preventing update loops
|
|
576
|
+
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
577
|
+
if (isActorStopped(self))
|
|
578
|
+
return;
|
|
554
579
|
if (context.schemaName) {
|
|
555
580
|
try {
|
|
556
581
|
const schema = Schema.create(context.schemaName, {
|
|
@@ -633,7 +658,11 @@ const validateModel = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
633
658
|
});
|
|
634
659
|
|
|
635
660
|
const logger$5 = debug('seedSdk:model:actors:createModelProperties');
|
|
636
|
-
const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
661
|
+
const createModelProperties = fromCallback(({ sendBack, input, self }) => {
|
|
662
|
+
// The model was stopped (unloaded, or evicted with its schema by Schema.destroy / test cleanup) while
|
|
663
|
+
// this ran: stopping it stops this actor too, but can't cancel the awaits below. A stopped model
|
|
664
|
+
// creates no properties (they'd be cached for a model that's gone, and write rows under it).
|
|
665
|
+
const stopped = () => isActorStopped(self);
|
|
637
666
|
const _createProperties = async () => {
|
|
638
667
|
const { context, propertyDefinitions } = input;
|
|
639
668
|
const { id, _dbId, modelName, schemaName } = context;
|
|
@@ -646,7 +675,7 @@ const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
|
646
675
|
return;
|
|
647
676
|
}
|
|
648
677
|
logger$5(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
|
|
649
|
-
const mod = await import('./ModelProperty-
|
|
678
|
+
const mod = await import('./ModelProperty-BMePcicQ.js');
|
|
650
679
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
651
680
|
if (!ModelProperty) {
|
|
652
681
|
logger$5('ModelProperty not available from dynamic import');
|
|
@@ -671,7 +700,9 @@ const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
|
671
700
|
: undefined;
|
|
672
701
|
// Otherwise use provided ID or generate a random one
|
|
673
702
|
// IDs should be generated in the import process before creating properties
|
|
674
|
-
const
|
|
703
|
+
const _mod_7 = await import('./tabEvents-C9qUKx_z.js');
|
|
704
|
+
const _ns_7 = _mod_7.P;
|
|
705
|
+
const { generateId } = _ns_7;
|
|
675
706
|
const propertyFileId = propData.id || propertyRecord?.schemaFileId || generateId();
|
|
676
707
|
logger$5(`Creating property "${propName}" with fileId "${propertyFileId}"`);
|
|
677
708
|
// Query database to get refModelId if the property has ref/refModelName
|
|
@@ -687,9 +718,9 @@ const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
|
687
718
|
}
|
|
688
719
|
else if (refModelName) {
|
|
689
720
|
// Fallback: resolve the ref by name within this model's schema
|
|
690
|
-
const
|
|
691
|
-
const
|
|
692
|
-
const { resolveModelRecord } =
|
|
721
|
+
const _mod_8 = await import('./db-W1g29qsM.js');
|
|
722
|
+
const _ns_8 = _mod_8.Y;
|
|
723
|
+
const { resolveModelRecord } = _ns_8;
|
|
693
724
|
const refModelRecord = await resolveModelRecord(refModelName, { schemaName }, db);
|
|
694
725
|
if (refModelRecord?.id) {
|
|
695
726
|
refModelId = refModelRecord.id;
|
|
@@ -702,6 +733,10 @@ const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
|
702
733
|
// Continue without refModelId - it will be resolved later in _initializeOriginalValues
|
|
703
734
|
}
|
|
704
735
|
}
|
|
736
|
+
if (stopped()) {
|
|
737
|
+
logger$5(`Model "${modelName}" was stopped while creating its properties; not creating the rest`);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
705
740
|
// Create ModelProperty instance
|
|
706
741
|
// This will load from DB if it exists, or create new instance
|
|
707
742
|
// The property should already be in DB from writeModelToDb
|
|
@@ -740,6 +775,37 @@ const createModelProperties = fromCallback(({ sendBack, input }) => {
|
|
|
740
775
|
};
|
|
741
776
|
});
|
|
742
777
|
|
|
778
|
+
/**
|
|
779
|
+
* Eviction epochs: lets work that was started before a schema's Model/ModelProperty instances were
|
|
780
|
+
* evicted (Schema.destroy, test cleanup) tell, when it finishes, that it must not put instances for
|
|
781
|
+
* that schema back in the caches. Stopping the evicted actors can't cancel such work (a DB lookup
|
|
782
|
+
* that ends in Model.create, a model's property creation), and finishing it after the eviction would
|
|
783
|
+
* rebuild instances from rows that are about to be deleted, which then write themselves again.
|
|
784
|
+
*
|
|
785
|
+
* Capture `currentEvictionEpoch()` when the work starts; before creating or caching an instance, skip
|
|
786
|
+
* it when `schemaEvictedSince(schemaName, epoch)`. Work started after an eviction is unaffected.
|
|
787
|
+
*/
|
|
788
|
+
let epoch = 0;
|
|
789
|
+
const lastEvictionBySchema = new Map();
|
|
790
|
+
function currentEvictionEpoch() {
|
|
791
|
+
return epoch;
|
|
792
|
+
}
|
|
793
|
+
/** Called by Model.evictForSchema. */
|
|
794
|
+
function recordSchemaEviction(schemaName) {
|
|
795
|
+
epoch += 1;
|
|
796
|
+
lastEvictionBySchema.set(schemaName, epoch);
|
|
797
|
+
}
|
|
798
|
+
/** True when the schema's instances were evicted after `since` (an epoch from currentEvictionEpoch). */
|
|
799
|
+
function schemaEvictedSince(schemaName, since) {
|
|
800
|
+
if (epoch === since || !schemaName)
|
|
801
|
+
return false;
|
|
802
|
+
return (lastEvictionBySchema.get(schemaName) ?? 0) > since;
|
|
803
|
+
}
|
|
804
|
+
/** True when any schema was evicted after `since` (cheap check before looking up which schemas apply). */
|
|
805
|
+
function anyEvictionSince(since) {
|
|
806
|
+
return epoch !== since;
|
|
807
|
+
}
|
|
808
|
+
|
|
743
809
|
const logger$4 = debug('seedSdk:write:validateEntity');
|
|
744
810
|
// XState v5 type inference bug: fromPromise types are inverted
|
|
745
811
|
// We use type assertion to work around this
|
|
@@ -747,6 +813,20 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
747
813
|
// Type assertion to fix XState v5 type inference bug
|
|
748
814
|
// Convert through unknown to avoid type overlap error
|
|
749
815
|
const entityInput = input;
|
|
816
|
+
// Validation awaits imports before looking up the schema; the entity can be evicted with its
|
|
817
|
+
// schema meanwhile (Schema.destroy, test cleanup). Schema.create would then load the evicted
|
|
818
|
+
// schema again, and its load re-creates the schema's models from rows being deleted.
|
|
819
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
820
|
+
/** The schema to validate against; throws (validation then skips the schema check) once it was evicted. */
|
|
821
|
+
const schemaForValidation = async (schemaName) => {
|
|
822
|
+
const _mod_9 = await import('./Schema-COsEXXaR.js');
|
|
823
|
+
const _ns_9 = _mod_9.b;
|
|
824
|
+
const { Schema } = _ns_9;
|
|
825
|
+
if (schemaEvictedSince(schemaName, evictionEpoch)) {
|
|
826
|
+
throw new Error(`Schema "${schemaName}" was evicted during validation`);
|
|
827
|
+
}
|
|
828
|
+
return Schema.create(schemaName, { waitForReady: false });
|
|
829
|
+
};
|
|
750
830
|
const _validate = async () => {
|
|
751
831
|
try {
|
|
752
832
|
const msg = `[validateEntity] Starting validation for ${entityInput.entityType}`;
|
|
@@ -757,7 +837,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
757
837
|
const structureMsg = `[validateEntity] Validating model structure`;
|
|
758
838
|
logger$4(structureMsg);
|
|
759
839
|
// Use existing Model validation
|
|
760
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
840
|
+
const validationServiceMod = await import('./SchemaValidationService-DabGMzSE.js');
|
|
761
841
|
const { SchemaValidationService } = validationServiceMod;
|
|
762
842
|
const validationService = new SchemaValidationService();
|
|
763
843
|
// Validate model structure
|
|
@@ -775,13 +855,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
775
855
|
if (entityInput.entityData.schemaName) {
|
|
776
856
|
try {
|
|
777
857
|
logger$4(`[validateEntity] Validating model against schema "${entityInput.entityData.schemaName}"`);
|
|
778
|
-
const
|
|
779
|
-
const _ns_8 = _mod_8.b;
|
|
780
|
-
const schemaMod = _ns_8;
|
|
781
|
-
const { Schema } = schemaMod;
|
|
782
|
-
const schema = Schema.create(entityInput.entityData.schemaName, {
|
|
783
|
-
waitForReady: false,
|
|
784
|
-
});
|
|
858
|
+
const schema = await schemaForValidation(entityInput.entityData.schemaName);
|
|
785
859
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
786
860
|
const schemaStatus = schemaSnapshot.value;
|
|
787
861
|
logger$4(`[validateEntity] Schema status: ${schemaStatus}`);
|
|
@@ -813,7 +887,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
813
887
|
}
|
|
814
888
|
else if (entityInput.entityType === 'modelProperty') {
|
|
815
889
|
// Use existing ModelProperty validation
|
|
816
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
890
|
+
const validationServiceMod = await import('./SchemaValidationService-DabGMzSE.js');
|
|
817
891
|
const { SchemaValidationService } = validationServiceMod;
|
|
818
892
|
const validationService = new SchemaValidationService();
|
|
819
893
|
// Validate property structure
|
|
@@ -828,13 +902,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
828
902
|
// If schema name and model name provided, validate against schema
|
|
829
903
|
if (entityInput.entityData._schemaName && entityInput.entityData.modelName) {
|
|
830
904
|
try {
|
|
831
|
-
const
|
|
832
|
-
const _ns_9 = _mod_9.b;
|
|
833
|
-
const schemaMod = _ns_9;
|
|
834
|
-
const { Schema } = schemaMod;
|
|
835
|
-
const schema = Schema.create(entityInput.entityData._schemaName, {
|
|
836
|
-
waitForReady: false,
|
|
837
|
-
});
|
|
905
|
+
const schema = await schemaForValidation(entityInput.entityData._schemaName);
|
|
838
906
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
839
907
|
const schemaStatus = schemaSnapshot.value;
|
|
840
908
|
if (schemaStatus === 'idle') {
|
|
@@ -859,7 +927,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
859
927
|
}
|
|
860
928
|
else if (entityInput.entityType === 'schema') {
|
|
861
929
|
// Schema validation - use existing validation
|
|
862
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
930
|
+
const validationServiceMod = await import('./SchemaValidationService-DabGMzSE.js');
|
|
863
931
|
const { SchemaValidationService } = validationServiceMod;
|
|
864
932
|
const validationService = new SchemaValidationService();
|
|
865
933
|
const schemaResult = validationService.validateSchema(entityInput.entityData);
|
|
@@ -948,7 +1016,7 @@ const writeToDatabase = fromCallback(({ sendBack, input }) => {
|
|
|
948
1016
|
// initial write completes is not overwritten by the stale requestWrite payload.
|
|
949
1017
|
let dataToWrite = input.entityData;
|
|
950
1018
|
try {
|
|
951
|
-
const mod = await import('./ModelProperty-
|
|
1019
|
+
const mod = await import('./ModelProperty-BMePcicQ.js');
|
|
952
1020
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
953
1021
|
if (ModelProperty && typeof ModelProperty.getById === 'function') {
|
|
954
1022
|
const instance = ModelProperty.getById(input.entityId);
|
|
@@ -1331,16 +1399,23 @@ const modelMachine = setup({
|
|
|
1331
1399
|
({ context, event, self }) => {
|
|
1332
1400
|
if (event._liveQueryPropertyIds !== undefined) {
|
|
1333
1401
|
const newPropertyIds = event._liveQueryPropertyIds;
|
|
1402
|
+
// The model can be evicted with its schema (Schema.destroy, test cleanup) before the
|
|
1403
|
+
// timer and import below run: then create nothing, and drop lookups an eviction overtakes.
|
|
1404
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
1334
1405
|
// Use setTimeout to check after assign has been applied
|
|
1335
1406
|
setTimeout(() => {
|
|
1336
|
-
self.getSnapshot();
|
|
1407
|
+
const snapshot = self.getSnapshot();
|
|
1408
|
+
if (snapshot.status === 'stopped')
|
|
1409
|
+
return;
|
|
1337
1410
|
// Create ModelProperty instances for any new property IDs
|
|
1338
1411
|
if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
|
|
1339
1412
|
// Import and create instances asynchronously (fire-and-forget)
|
|
1340
|
-
import('./ModelProperty-
|
|
1413
|
+
import('./ModelProperty-BMePcicQ.js').then(({ ModelProperty }) => {
|
|
1414
|
+
if (self.getSnapshot().status === 'stopped')
|
|
1415
|
+
return;
|
|
1341
1416
|
const createPromises = newPropertyIds.map(async (propertyFileId) => {
|
|
1342
1417
|
try {
|
|
1343
|
-
const property = await ModelProperty.createById(propertyFileId);
|
|
1418
|
+
const property = await ModelProperty.createById(propertyFileId, { evictionEpoch });
|
|
1344
1419
|
if (property) {
|
|
1345
1420
|
logger$1(`[modelMachine] Created/cached ModelProperty instance for propertyFileId "${propertyFileId}" after _liveQueryPropertyIds update`);
|
|
1346
1421
|
}
|
|
@@ -1638,22 +1713,6 @@ class ConflictError extends Error {
|
|
|
1638
1713
|
}
|
|
1639
1714
|
}
|
|
1640
1715
|
|
|
1641
|
-
/**
|
|
1642
|
-
* Common getters and utilities for entity classes
|
|
1643
|
-
* These work with any entity that has a getService() method returning an XState actor
|
|
1644
|
-
*/
|
|
1645
|
-
/**
|
|
1646
|
-
* Get the current state value from an entity's service
|
|
1647
|
-
*/
|
|
1648
|
-
/**
|
|
1649
|
-
* Whether an actor has been stopped (unload, destroy, or Schema eviction). Async work started by an
|
|
1650
|
-
* entity (DB lookups, retry timers) must check this before sending, since a stopped actor ignores
|
|
1651
|
-
* events and XState warns about every one of them.
|
|
1652
|
-
*/
|
|
1653
|
-
function isActorStopped(actor) {
|
|
1654
|
-
return actor.getSnapshot().status === 'stopped';
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
1716
|
/**
|
|
1658
1717
|
* Set up liveQuery subscription for an entity
|
|
1659
1718
|
* This enables cross-instance synchronization (e.g., changes in other tabs/windows)
|
|
@@ -1679,7 +1738,10 @@ function setupEntityLiveQuery(instance, config) {
|
|
|
1679
1738
|
const initialIds = config.extractEntityIds(initialRows);
|
|
1680
1739
|
if (initialIds.length > 0) {
|
|
1681
1740
|
logger(`Initial query returned ${initialIds.length} entities`);
|
|
1682
|
-
// Create child instances if provided
|
|
1741
|
+
// Create child instances if provided (not for a stopped entity: an unloaded or evicted
|
|
1742
|
+
// parent must not re-cache its children)
|
|
1743
|
+
if (isActorStopped(instance.getService()))
|
|
1744
|
+
return;
|
|
1683
1745
|
if (config.createChildInstances) {
|
|
1684
1746
|
await config.createChildInstances(initialIds);
|
|
1685
1747
|
}
|
|
@@ -1710,7 +1772,9 @@ function setupEntityLiveQuery(instance, config) {
|
|
|
1710
1772
|
}
|
|
1711
1773
|
logger(`Query returned ${rows.length} rows`);
|
|
1712
1774
|
const ids = config.extractEntityIds(rows);
|
|
1713
|
-
// Create child instances if provided (before updating context)
|
|
1775
|
+
// Create child instances if provided (before updating context; not for a stopped entity)
|
|
1776
|
+
if (isActorStopped(instance.getService()))
|
|
1777
|
+
return;
|
|
1714
1778
|
if (config.createChildInstances && ids.length > 0) {
|
|
1715
1779
|
await config.createChildInstances(ids);
|
|
1716
1780
|
}
|
|
@@ -1851,7 +1915,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
|
|
|
1851
1915
|
// Lazy import cache for ModelProperty to avoid circular dependency
|
|
1852
1916
|
// Eagerly start loading to minimize delay on first access
|
|
1853
1917
|
let ModelPropertyClass = null;
|
|
1854
|
-
const modelPropertyImportPromise = import('./ModelProperty-
|
|
1918
|
+
const modelPropertyImportPromise = import('./ModelProperty-BMePcicQ.js')
|
|
1855
1919
|
.then(module => {
|
|
1856
1920
|
ModelPropertyClass = module.ModelProperty;
|
|
1857
1921
|
return ModelPropertyClass;
|
|
@@ -1867,7 +1931,7 @@ function getModelProperty() {
|
|
|
1867
1931
|
return ModelPropertyClass;
|
|
1868
1932
|
}
|
|
1869
1933
|
// Lazy import for Schema to avoid circular dependency
|
|
1870
|
-
const schemaImportPromise = (async () => { const _mod_12 = await import('./Schema-
|
|
1934
|
+
const schemaImportPromise = (async () => { const _mod_12 = await import('./Schema-COsEXXaR.js'); return _mod_12.b; })()
|
|
1871
1935
|
.then(module => module.Schema)
|
|
1872
1936
|
.catch(() => null);
|
|
1873
1937
|
// WeakMap to store mutable state per Model instance
|
|
@@ -2365,6 +2429,9 @@ class Model {
|
|
|
2365
2429
|
resolve();
|
|
2366
2430
|
}, 10000);
|
|
2367
2431
|
});
|
|
2432
|
+
// Unloaded or evicted (e.g. Schema.destroy) while it loaded: a stopped model never writes
|
|
2433
|
+
if (isActorStopped(proxiedInstance._service))
|
|
2434
|
+
return;
|
|
2368
2435
|
// Only write if validation passed (model is in idle state, not error)
|
|
2369
2436
|
const finalSnapshot = proxiedInstance._service.getSnapshot();
|
|
2370
2437
|
if (finalSnapshot.value === 'idle' && (!finalSnapshot.context._validationErrors || finalSnapshot.context._validationErrors.length === 0)) {
|
|
@@ -2488,8 +2555,8 @@ class Model {
|
|
|
2488
2555
|
}
|
|
2489
2556
|
logger(`WARNING: Could not verify schema exists in database: ${error}. Proceeding anyway.`);
|
|
2490
2557
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2558
|
+
const pendingModelFileId = finalSnapshot.context.id;
|
|
2559
|
+
const pendingSchemaId = schemaId;
|
|
2493
2560
|
// Wait for writeProcess to be spawned (it's spawned in idle state entry action)
|
|
2494
2561
|
// Retry a few times if writeProcess isn't available yet
|
|
2495
2562
|
let retries = 0;
|
|
@@ -2500,6 +2567,8 @@ class Model {
|
|
|
2500
2567
|
return;
|
|
2501
2568
|
const currentSnapshot = proxiedInstance._service.getSnapshot();
|
|
2502
2569
|
if (currentSnapshot.context.writeProcess) {
|
|
2570
|
+
// Track pending write (only once it really starts: a stopped model leaves none behind)
|
|
2571
|
+
Model.trackPendingWrite(pendingModelFileId, pendingSchemaId); // id is now the schemaFileId (string)
|
|
2503
2572
|
logger(`Triggering write process for model "${finalSnapshot.context.modelName}" (schemaId: ${schemaId})`);
|
|
2504
2573
|
// Use pending property definitions if available, otherwise convert from ModelProperty instances
|
|
2505
2574
|
let propertiesObject = {};
|
|
@@ -2720,6 +2789,7 @@ class Model {
|
|
|
2720
2789
|
if (scope.modelFileId || scope.schemaName) {
|
|
2721
2790
|
const db = BaseDb.getAppDb();
|
|
2722
2791
|
if (db) {
|
|
2792
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
2723
2793
|
try {
|
|
2724
2794
|
const rows = await db
|
|
2725
2795
|
.select({
|
|
@@ -2736,6 +2806,9 @@ class Model {
|
|
|
2736
2806
|
.limit(1);
|
|
2737
2807
|
const record = rows[0];
|
|
2738
2808
|
if (record?.modelName && record.schemaName && record.modelFileId) {
|
|
2809
|
+
// Its schema was evicted while we read the row: don't bring the model back.
|
|
2810
|
+
if (schemaEvictedSince(record.schemaName, evictionEpoch))
|
|
2811
|
+
return undefined;
|
|
2739
2812
|
return this.create(record.modelName, record.schemaName, { id: record.modelFileId });
|
|
2740
2813
|
}
|
|
2741
2814
|
}
|
|
@@ -2754,7 +2827,7 @@ class Model {
|
|
|
2754
2827
|
* @param schemaName - Optional schema name (will query DB if not provided)
|
|
2755
2828
|
* @returns The Model instance if found, undefined otherwise
|
|
2756
2829
|
*/
|
|
2757
|
-
static async getByNameAsync(modelName, schemaName) {
|
|
2830
|
+
static async getByNameAsync(modelName, schemaName, options) {
|
|
2758
2831
|
// First try cache
|
|
2759
2832
|
const cached = this.getByName(modelName, schemaName);
|
|
2760
2833
|
if (cached) {
|
|
@@ -2766,9 +2839,10 @@ class Model {
|
|
|
2766
2839
|
if (!db) {
|
|
2767
2840
|
return undefined;
|
|
2768
2841
|
}
|
|
2842
|
+
const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
|
|
2769
2843
|
try {
|
|
2770
2844
|
// Query model by name (throws AmbiguousModelError when several schemas define it)
|
|
2771
|
-
const _mod_10 = await import('./db-
|
|
2845
|
+
const _mod_10 = await import('./db-W1g29qsM.js');
|
|
2772
2846
|
const _ns_10 = _mod_10.Y;
|
|
2773
2847
|
const { resolveModelRecord } = _ns_10;
|
|
2774
2848
|
const resolved = await resolveModelRecord(modelName, {}, db);
|
|
@@ -2793,6 +2867,10 @@ class Model {
|
|
|
2793
2867
|
if (!record.modelName || !record.schemaName || !record.modelFileId) {
|
|
2794
2868
|
return undefined;
|
|
2795
2869
|
}
|
|
2870
|
+
// Its schema was evicted while we read the row: don't bring the model back.
|
|
2871
|
+
if (schemaEvictedSince(record.schemaName, evictionEpoch)) {
|
|
2872
|
+
return undefined;
|
|
2873
|
+
}
|
|
2796
2874
|
// Create model instance (will be cached)
|
|
2797
2875
|
return this.create(record.modelName, record.schemaName, {
|
|
2798
2876
|
id: record.modelFileId, // id is now the schemaFileId (string)
|
|
@@ -2814,7 +2892,7 @@ class Model {
|
|
|
2814
2892
|
* @param modelFileId - The model file ID to look up
|
|
2815
2893
|
* @returns The Model instance if found, undefined otherwise
|
|
2816
2894
|
*/
|
|
2817
|
-
static async createById(modelFileId) {
|
|
2895
|
+
static async createById(modelFileId, options) {
|
|
2818
2896
|
if (!modelFileId) {
|
|
2819
2897
|
return undefined;
|
|
2820
2898
|
}
|
|
@@ -2830,6 +2908,7 @@ class Model {
|
|
|
2830
2908
|
logger(`Model.createById: Database not available for ID "${modelFileId}"`);
|
|
2831
2909
|
return undefined;
|
|
2832
2910
|
}
|
|
2911
|
+
const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
|
|
2833
2912
|
try {
|
|
2834
2913
|
// Query model by schemaFileId and join to get schema name
|
|
2835
2914
|
const modelRecords = await db
|
|
@@ -2852,6 +2931,12 @@ class Model {
|
|
|
2852
2931
|
logger(`Model.createById: Missing modelName or schemaName for ID "${modelFileId}"`);
|
|
2853
2932
|
return undefined;
|
|
2854
2933
|
}
|
|
2934
|
+
// Its schema was evicted while we read the row (e.g. a Schema live query in flight during
|
|
2935
|
+
// Schema.destroy or test cleanup): don't bring the model back.
|
|
2936
|
+
if (schemaEvictedSince(schemaName, evictionEpoch)) {
|
|
2937
|
+
logger(`Model.createById: schema "${schemaName}" was evicted during the lookup of "${modelFileId}"`);
|
|
2938
|
+
return undefined;
|
|
2939
|
+
}
|
|
2855
2940
|
// Step 3: Create model using existing create method (which will handle caching)
|
|
2856
2941
|
logger(`Model.createById: Creating model "${modelName}" in schema "${schemaName}" from ID "${modelFileId}"`);
|
|
2857
2942
|
return this.create(modelName, schemaName, {
|
|
@@ -2906,6 +2991,7 @@ class Model {
|
|
|
2906
2991
|
logger(`Model.createBySchemaId: Database not available for schema "${schemaIdentifier}"`);
|
|
2907
2992
|
return [];
|
|
2908
2993
|
}
|
|
2994
|
+
const evictionEpoch = currentEvictionEpoch();
|
|
2909
2995
|
try {
|
|
2910
2996
|
// Query all models for this schema - support both schemaFileId and schema name
|
|
2911
2997
|
const modelRecords = await db
|
|
@@ -2928,6 +3014,10 @@ class Model {
|
|
|
2928
3014
|
if (!record.modelName || !record.schemaName || !record.modelFileId) {
|
|
2929
3015
|
continue;
|
|
2930
3016
|
}
|
|
3017
|
+
// Its schema was evicted while we read the rows: don't bring its models back.
|
|
3018
|
+
if (schemaEvictedSince(record.schemaName, evictionEpoch)) {
|
|
3019
|
+
continue;
|
|
3020
|
+
}
|
|
2931
3021
|
// Check cache first
|
|
2932
3022
|
const cached = this.getById(record.modelFileId);
|
|
2933
3023
|
if (cached) {
|
|
@@ -3374,6 +3464,8 @@ class Model {
|
|
|
3374
3464
|
* @returns names of the evicted models (so callers can evict their ModelProperty instances)
|
|
3375
3465
|
*/
|
|
3376
3466
|
static evictForSchema(schemaName) {
|
|
3467
|
+
// Work already running for this schema's models must not re-cache them when it finishes.
|
|
3468
|
+
recordSchemaEviction(schemaName);
|
|
3377
3469
|
const instances = new Set();
|
|
3378
3470
|
for (const { instance } of this.instanceCacheById.values())
|
|
3379
3471
|
instances.add(instance);
|
|
@@ -3526,7 +3618,7 @@ class Model {
|
|
|
3526
3618
|
return undefined;
|
|
3527
3619
|
}
|
|
3528
3620
|
// Model names are only unique per schema: find this model's row by its id (schemaFileId).
|
|
3529
|
-
const _mod_11 = await import('./db-
|
|
3621
|
+
const _mod_11 = await import('./db-W1g29qsM.js');
|
|
3530
3622
|
const _ns_11 = _mod_11.Y;
|
|
3531
3623
|
const { resolveModelRecord } = _ns_11;
|
|
3532
3624
|
const modelRecord = await resolveModelRecord(modelName, { modelFileId: context.id, schemaName: context.schemaName }, db);
|
|
@@ -3731,5 +3823,5 @@ var Model$1 = /*#__PURE__*/Object.freeze({
|
|
|
3731
3823
|
const TModelValues = Type.Record(Type.String(), Type.Any());
|
|
3732
3824
|
const TModelSchema = Type.Record(Type.String(), TProperty);
|
|
3733
3825
|
|
|
3734
|
-
export { ConflictError as C, Model as M, TModelSchema as T, TModelValues as a, writeToDatabase$1 as
|
|
3735
|
-
//# sourceMappingURL=index-
|
|
3826
|
+
export { ConflictError as C, Model as M, TModelSchema as T, TModelValues as a, anyEvictionSince as b, currentEvictionEpoch as c, setupEntityLiveQuery as d, writeToDatabase$1 as e, Model$1 as f, isActorStopped as i, schemaEvictedSince as s, writeProcessMachine as w };
|
|
3827
|
+
//# sourceMappingURL=index-DRXC5Mra.js.map
|