@seedprotocol/sdk 0.7.7 → 0.7.8-next.1034.g2acd2a2
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/{ClientManager-2GtDWHq6.js → ClientManager-DBKvmJov.js} +64 -36
- package/dist/ClientManager-DBKvmJov.js.map +1 -0
- package/dist/{Item-D6j0IvBP.js → Item-BiMHgg-_.js} +539 -486
- package/dist/Item-BiMHgg-_.js.map +1 -0
- package/dist/{ModelProperty-B52C3CQ2.js → ModelProperty-C1Fzcnbm.js} +50 -51
- package/dist/ModelProperty-C1Fzcnbm.js.map +1 -0
- package/dist/{Schema-O1QLoXv6.js → Schema-COTbavcm.js} +97 -82
- package/dist/Schema-COTbavcm.js.map +1 -0
- package/dist/{SchemaValidationService-BxCbfDaI.js → SchemaValidationService-paOfbcwd.js} +6 -6
- package/dist/{SchemaValidationService-BxCbfDaI.js.map → SchemaValidationService-paOfbcwd.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-CzSbuucw.js → backfillMetadataPropertyIds-BkpBahbz.js} +3 -3
- package/dist/{backfillMetadataPropertyIds-CzSbuucw.js.map → backfillMetadataPropertyIds-BkpBahbz.js.map} +1 -1
- package/dist/{configurePlatform-Bbpw_R4y.js → configurePlatform-_XR45RnJ.js} +2 -2
- package/dist/{configurePlatform-Bbpw_R4y.js.map → configurePlatform-_XR45RnJ.js.map} +1 -1
- package/dist/{detachRowsBeforeDelete-D1TyEMco.js → detachRowsBeforeDelete-C1iapUFl.js} +2 -2
- package/dist/{detachRowsBeforeDelete-D1TyEMco.js.map → detachRowsBeforeDelete-C1iapUFl.js.map} +1 -1
- package/dist/{discardNewDraft-hiVaUVjV.js → discardNewDraft-D4nrwp3T.js} +5 -5
- package/dist/{discardNewDraft-hiVaUVjV.js.map → discardNewDraft-D4nrwp3T.js.map} +1 -1
- package/dist/dist/{ClientManager-2GtDWHq6.d.ts → ClientManager-DBKvmJov.d.ts} +20 -1
- package/dist/dist/ClientManager-DBKvmJov.d.ts.map +1 -0
- package/dist/dist/{Item-D6j0IvBP.d.ts → Item-BiMHgg-_.d.ts} +146 -85
- package/dist/dist/Item-BiMHgg-_.d.ts.map +1 -0
- package/dist/dist/{ModelProperty-B52C3CQ2.d.ts → ModelProperty-C1Fzcnbm.d.ts} +1 -1
- package/dist/dist/{ModelProperty-B52C3CQ2.d.ts.map → ModelProperty-C1Fzcnbm.d.ts.map} +1 -1
- package/dist/dist/{Schema-O1QLoXv6.d.ts → Schema-COTbavcm.d.ts} +11 -4
- package/dist/dist/Schema-COTbavcm.d.ts.map +1 -0
- package/dist/dist/{SchemaValidationService-BxCbfDaI.d.ts → SchemaValidationService-paOfbcwd.d.ts} +1 -1
- package/dist/dist/{SchemaValidationService-BxCbfDaI.d.ts.map → SchemaValidationService-paOfbcwd.d.ts.map} +1 -1
- package/dist/dist/{backfillMetadataPropertyIds-CzSbuucw.d.ts → backfillMetadataPropertyIds-BkpBahbz.d.ts} +1 -1
- package/dist/dist/backfillMetadataPropertyIds-BkpBahbz.d.ts.map +1 -0
- package/dist/dist/{configurePlatform-Bbpw_R4y.d.ts → configurePlatform-_XR45RnJ.d.ts} +1 -1
- package/dist/dist/configurePlatform-_XR45RnJ.d.ts.map +1 -0
- package/dist/dist/{detachRowsBeforeDelete-D1TyEMco.d.ts → detachRowsBeforeDelete-C1iapUFl.d.ts} +1 -1
- package/dist/dist/detachRowsBeforeDelete-C1iapUFl.d.ts.map +1 -0
- package/dist/dist/{discardNewDraft-hiVaUVjV.d.ts → discardNewDraft-D4nrwp3T.d.ts} +1 -1
- package/dist/dist/discardNewDraft-D4nrwp3T.d.ts.map +1 -0
- package/dist/dist/{eas-DOdj-EMK.d.ts → eas-BRVEGT97.d.ts} +1 -1
- package/dist/dist/eas-BRVEGT97.d.ts.map +1 -0
- package/dist/dist/{errors-KM-yq2MD.d.ts → errors-CQagdED2.d.ts} +39 -24
- package/dist/dist/errors-CQagdED2.d.ts.map +1 -0
- package/dist/dist/{getItem-Bh0zv-o1.d.ts → getItem-Jpr1SKIL.d.ts} +1 -1
- package/dist/dist/getItem-Jpr1SKIL.d.ts.map +1 -0
- package/dist/dist/{getPublishPayload-oH8wJhnH.d.ts → getPublishPayload-Bmeqtq4l.d.ts} +1 -1
- package/dist/dist/{getPublishPayload-oH8wJhnH.d.ts.map → getPublishPayload-Bmeqtq4l.d.ts.map} +1 -1
- package/dist/dist/{getPublishUploads-Cex-NBe6.d.ts → getPublishUploads-7nW1kMZV.d.ts} +1 -1
- package/dist/dist/{getPublishUploads-Cex-NBe6.d.ts.map → getPublishUploads-7nW1kMZV.d.ts.map} +1 -1
- package/dist/dist/{index-BbFwftAv.d.ts → index-3_hGVu7v.d.ts} +1 -1
- package/dist/dist/{index-BbFwftAv.d.ts.map → index-3_hGVu7v.d.ts.map} +1 -1
- package/dist/dist/{index-DpgQMIRq.d.ts → index-C-NqjjY_.d.ts} +11 -5
- package/dist/dist/index-C-NqjjY_.d.ts.map +1 -0
- package/dist/dist/{index-BAao3_Po.d.ts → index-DM3zrNtX.d.ts} +5 -5
- package/dist/dist/index-DM3zrNtX.d.ts.map +1 -0
- package/dist/dist/{index.browser-nndbVM7z.d.ts → index.browser-DGoOSs1J.d.ts} +1 -1
- package/dist/dist/{index.browser-nndbVM7z.d.ts.map → index.browser-DGoOSs1J.d.ts.map} +1 -1
- package/dist/dist/{index.node-BUfx-JaP.d.ts → index.node-CTv62R2a.d.ts} +1 -1
- package/dist/dist/{index.node-BUfx-JaP.d.ts.map → index.node-CTv62R2a.d.ts.map} +1 -1
- package/dist/dist/platform.browser.d.ts +2 -2
- package/dist/dist/platform.node.d.ts +2 -2
- package/dist/dist/{property-BDBvImLs.d.ts → property-DaUy4XMe.d.ts} +3 -3
- package/dist/dist/property-DaUy4XMe.d.ts.map +1 -0
- package/dist/dist/{propertyValidationRules-BlfLn4rP.d.ts → propertyValidationRules-DbbWvBzj.d.ts} +1 -1
- package/dist/dist/propertyValidationRules-DbbWvBzj.d.ts.map +1 -0
- package/dist/dist/{publishDraftGraph-CLO85LLz.d.ts → publishDraftGraph-CCa6EzeO.d.ts} +1 -1
- package/dist/dist/{publishDraftGraph-CLO85LLz.d.ts.map → publishDraftGraph-CCa6EzeO.d.ts.map} +1 -1
- package/dist/dist/{resetAmbiguousLegacyItemData-Cy8ik7xk.d.ts → resetAmbiguousLegacyItemData--PN1v53N.d.ts} +1 -1
- package/dist/dist/resetAmbiguousLegacyItemData--PN1v53N.d.ts.map +1 -0
- package/dist/dist/{resolveModelForSyncedSeed-DFr4COc4.d.ts → resolveModelForSyncedSeed-VDzkS6Rs.d.ts} +1 -1
- package/dist/dist/resolveModelForSyncedSeed-VDzkS6Rs.d.ts.map +1 -0
- package/dist/dist/{syncDbWithEas-CAOlw3i-.d.ts → syncDbWithEas-D0gyJ58h.d.ts} +1 -1
- package/dist/dist/syncDbWithEas-D0gyJ58h.d.ts.map +1 -0
- package/dist/dist/{tabEvents-DksXwk3X.d.ts → tabEvents-UH-wNsZC.d.ts} +7 -4
- package/dist/dist/tabEvents-UH-wNsZC.d.ts.map +1 -0
- package/dist/dist/{tolerantWebAccess-CEIjFGf0.d.ts → tolerantWebAccess-CpcTCAZv.d.ts} +1 -1
- package/dist/dist/{tolerantWebAccess-CEIjFGf0.d.ts.map → tolerantWebAccess-CpcTCAZv.d.ts.map} +1 -1
- package/dist/dist/{updateSeedRevokedAt-Cjr35YjE.d.ts → updateSeedRevokedAt-D230zfWk.d.ts} +1 -1
- package/dist/dist/updateSeedRevokedAt-D230zfWk.d.ts.map +1 -0
- package/dist/{eas-DOdj-EMK.js → eas-BRVEGT97.js} +4 -4
- package/dist/{eas-DOdj-EMK.js.map → eas-BRVEGT97.js.map} +1 -1
- package/dist/{errors-KM-yq2MD.js → errors-CQagdED2.js} +222 -275
- package/dist/errors-CQagdED2.js.map +1 -0
- package/dist/{getItem-Bh0zv-o1.js → getItem-Jpr1SKIL.js} +4 -4
- package/dist/{getItem-Bh0zv-o1.js.map → getItem-Jpr1SKIL.js.map} +1 -1
- package/dist/{getPublishPayload-oH8wJhnH.js → getPublishPayload-Bmeqtq4l.js} +15 -15
- package/dist/{getPublishPayload-oH8wJhnH.js.map → getPublishPayload-Bmeqtq4l.js.map} +1 -1
- package/dist/{getPublishUploads-Cex-NBe6.js → getPublishUploads-7nW1kMZV.js} +6 -6
- package/dist/{getPublishUploads-Cex-NBe6.js.map → getPublishUploads-7nW1kMZV.js.map} +1 -1
- package/dist/{index-BbFwftAv.js → index-3_hGVu7v.js} +2 -2
- package/dist/index-3_hGVu7v.js.map +1 -0
- package/dist/{index-DpgQMIRq.js → index-C-NqjjY_.js} +18 -3
- package/dist/index-C-NqjjY_.js.map +1 -0
- package/dist/{index-BAao3_Po.js → index-DM3zrNtX.js} +8 -8
- package/dist/index-DM3zrNtX.js.map +1 -0
- package/dist/{index.browser-nndbVM7z.js → index.browser-DGoOSs1J.js} +27 -18
- package/dist/index.browser-DGoOSs1J.js.map +1 -0
- package/dist/{index.node-BUfx-JaP.js → index.node-CTv62R2a.js} +6 -6
- package/dist/{index.node-BUfx-JaP.js.map → index.node-CTv62R2a.js.map} +1 -1
- package/dist/main.js +24 -24
- package/dist/node.js +11 -11
- package/dist/platform.browser.js +5 -5
- package/dist/platform.node.js +4 -4
- package/dist/{property-BDBvImLs.js → property-DaUy4XMe.js} +9 -11
- package/dist/property-DaUy4XMe.js.map +1 -0
- package/dist/{propertyValidationRules-BlfLn4rP.js → propertyValidationRules-DbbWvBzj.js} +10 -10
- package/dist/{propertyValidationRules-BlfLn4rP.js.map → propertyValidationRules-DbbWvBzj.js.map} +1 -1
- package/dist/{publishDraftGraph-CLO85LLz.js → publishDraftGraph-CCa6EzeO.js} +6 -6
- package/dist/{publishDraftGraph-CLO85LLz.js.map → publishDraftGraph-CCa6EzeO.js.map} +1 -1
- package/dist/{resetAmbiguousLegacyItemData-Cy8ik7xk.js → resetAmbiguousLegacyItemData--PN1v53N.js} +2 -2
- package/dist/{resetAmbiguousLegacyItemData-Cy8ik7xk.js.map → resetAmbiguousLegacyItemData--PN1v53N.js.map} +1 -1
- package/dist/{resolveModelForSyncedSeed-DFr4COc4.js → resolveModelForSyncedSeed-VDzkS6Rs.js} +2 -2
- package/dist/{resolveModelForSyncedSeed-DFr4COc4.js.map → resolveModelForSyncedSeed-VDzkS6Rs.js.map} +1 -1
- package/dist/src/Item/Item.d.ts +23 -6
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/Item/service/itemMachineSingle.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts +38 -6
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts.map +1 -1
- package/dist/src/Model/Model.d.ts +50 -9
- package/dist/src/Model/Model.d.ts.map +1 -1
- package/dist/src/Model/service/actors/validateModel.d.ts.map +1 -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/validateProperty.d.ts.map +1 -1
- package/dist/src/Schema/Schema.d.ts +22 -3
- 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/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +13 -0
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityCache.d.ts +2 -42
- package/dist/src/helpers/entity/entityCache.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityCommon.d.ts +9 -0
- package/dist/src/helpers/entity/entityCommon.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityDestroy.d.ts +13 -7
- package/dist/src/helpers/entity/entityDestroy.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityLiveQuery.d.ts +3 -2
- package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
- package/dist/src/helpers/entity/entityState.d.ts +28 -0
- package/dist/src/helpers/entity/entityState.d.ts.map +1 -0
- package/dist/src/helpers/entity/entityUnload.d.ts +3 -2
- package/dist/src/helpers/entity/entityUnload.d.ts.map +1 -1
- package/dist/src/helpers/entity/index.d.ts +1 -0
- package/dist/src/helpers/entity/index.d.ts.map +1 -1
- package/dist/src/helpers/metadataPropertyNames.d.ts +6 -0
- package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -1
- package/dist/src/helpers/property.d.ts.map +1 -1
- package/dist/src/helpers/reactiveProxy.d.ts +18 -0
- package/dist/src/helpers/reactiveProxy.d.ts.map +1 -1
- package/dist/src/helpers/sessionObjectUrls.d.ts +4 -0
- package/dist/src/helpers/sessionObjectUrls.d.ts.map +1 -0
- package/dist/src/imports/json.d.ts.map +1 -1
- package/dist/{syncDbWithEas-CAOlw3i-.js → syncDbWithEas-D0gyJ58h.js} +19 -19
- package/dist/syncDbWithEas-D0gyJ58h.js.map +1 -0
- package/dist/{tabEvents-DksXwk3X.js → tabEvents-UH-wNsZC.js} +24 -7
- package/dist/tabEvents-UH-wNsZC.js.map +1 -0
- package/dist/{tolerantWebAccess-CEIjFGf0.js → tolerantWebAccess-CpcTCAZv.js} +6 -6
- package/dist/{tolerantWebAccess-CEIjFGf0.js.map → tolerantWebAccess-CpcTCAZv.js.map} +1 -1
- package/dist/{updateSeedRevokedAt-Cjr35YjE.js → updateSeedRevokedAt-D230zfWk.js} +3 -3
- package/dist/{updateSeedRevokedAt-Cjr35YjE.js.map → updateSeedRevokedAt-D230zfWk.js.map} +1 -1
- package/package.json +6 -6
- package/dist/ClientManager-2GtDWHq6.js.map +0 -1
- package/dist/Item-D6j0IvBP.js.map +0 -1
- package/dist/ModelProperty-B52C3CQ2.js.map +0 -1
- package/dist/Schema-O1QLoXv6.js.map +0 -1
- package/dist/dist/ClientManager-2GtDWHq6.d.ts.map +0 -1
- package/dist/dist/Item-D6j0IvBP.d.ts.map +0 -1
- package/dist/dist/Schema-O1QLoXv6.d.ts.map +0 -1
- package/dist/dist/backfillMetadataPropertyIds-CzSbuucw.d.ts.map +0 -1
- package/dist/dist/configurePlatform-Bbpw_R4y.d.ts.map +0 -1
- package/dist/dist/detachRowsBeforeDelete-D1TyEMco.d.ts.map +0 -1
- package/dist/dist/discardNewDraft-hiVaUVjV.d.ts.map +0 -1
- package/dist/dist/eas-DOdj-EMK.d.ts.map +0 -1
- package/dist/dist/errors-KM-yq2MD.d.ts.map +0 -1
- package/dist/dist/getItem-Bh0zv-o1.d.ts.map +0 -1
- package/dist/dist/index-BAao3_Po.d.ts.map +0 -1
- package/dist/dist/index-DpgQMIRq.d.ts.map +0 -1
- package/dist/dist/property-BDBvImLs.d.ts.map +0 -1
- package/dist/dist/propertyValidationRules-BlfLn4rP.d.ts.map +0 -1
- package/dist/dist/resetAmbiguousLegacyItemData-Cy8ik7xk.d.ts.map +0 -1
- package/dist/dist/resolveModelForSyncedSeed-DFr4COc4.d.ts.map +0 -1
- package/dist/dist/syncDbWithEas-CAOlw3i-.d.ts.map +0 -1
- package/dist/dist/tabEvents-DksXwk3X.d.ts.map +0 -1
- package/dist/dist/updateSeedRevokedAt-Cjr35YjE.d.ts.map +0 -1
- package/dist/errors-KM-yq2MD.js.map +0 -1
- package/dist/index-BAao3_Po.js.map +0 -1
- package/dist/index-BbFwftAv.js.map +0 -1
- package/dist/index-DpgQMIRq.js.map +0 -1
- package/dist/index.browser-nndbVM7z.js.map +0 -1
- package/dist/property-BDBvImLs.js.map +0 -1
- package/dist/syncDbWithEas-CAOlw3i-.js.map +0 -1
- package/dist/tabEvents-DksXwk3X.js.map +0 -1
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
import { fromCallback, fromPromise, setup, assign, createActor } from 'xstate';
|
|
2
|
-
import { B as BaseDb, t as models, v as properties,
|
|
2
|
+
import { B as BaseDb, t as models, v as properties, ah as generateId, aJ as isInternalSchema, aK as writeModelToDb, aL as writePropertyToDb, aM as addSchemaToDb, r as modelSchemas, A as schemas, H as AmbiguousModelError, aN as renameModelInDb, aO as currentNameMatchLevels, a as TProperty } from './index-C-NqjjY_.js';
|
|
3
3
|
import { eq, and, isNull, or } from 'drizzle-orm';
|
|
4
4
|
import debug from 'debug';
|
|
5
|
-
import { d as waitForEntityIdle, D as DEFAULT_READY_TIMEOUT_MS,
|
|
6
|
-
import { m as getClient } from './ClientManager-
|
|
5
|
+
import { m as isActorStopped, $ as ActorKeyedState, d as waitForEntityIdle, D as DEFAULT_READY_TIMEOUT_MS, n as createReactiveProxy, q as findEntity, C as ClientManagerState, I as Item, a0 as clearDestroySubscriptions, t as forceRemoveFromCaches, a1 as unloadEntity, u as runDestroyLifecycle } from './Item-BiMHgg-_.js';
|
|
6
|
+
import { m as getClient } from './ClientManager-DBKvmJov.js';
|
|
7
7
|
import { modelPropertiesToObject } from './model-oHA3YhOd.js';
|
|
8
8
|
import { localNamesInBestMatchTier } from '@seedprotocol/eas';
|
|
9
9
|
import { Type } from '@sinclair/typebox';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Common getters and utilities for entity classes
|
|
13
|
-
* These work with any entity that has a getService() method returning an XState actor
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Get the current state value from an entity's service
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Whether an actor has been stopped (unload, destroy, or Schema eviction). Async work started by an
|
|
20
|
-
* entity (DB lookups, retry timers) must check this before sending, since a stopped actor ignores
|
|
21
|
-
* events and XState warns about every one of them.
|
|
22
|
-
*/
|
|
23
|
-
function isActorStopped(actor) {
|
|
24
|
-
return actor.getSnapshot().status === 'stopped';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
11
|
const logger$7 = debug('seedSdk:model:actors:loadOrCreateModel');
|
|
28
12
|
/**
|
|
29
13
|
* Create ModelProperty instances for all property IDs to ensure they're cached
|
|
@@ -35,7 +19,7 @@ const createPropertyInstances = async (propertyFileIds) => {
|
|
|
35
19
|
return;
|
|
36
20
|
}
|
|
37
21
|
try {
|
|
38
|
-
const mod = await import('./ModelProperty-
|
|
22
|
+
const mod = await import('./ModelProperty-C1Fzcnbm.js');
|
|
39
23
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
40
24
|
if (!ModelProperty) {
|
|
41
25
|
logger$7('createPropertyInstances: ModelProperty not available from dynamic import');
|
|
@@ -101,11 +85,11 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
|
|
|
101
85
|
if (!modelRecord) {
|
|
102
86
|
// Model names are only unique per schema: prefer this schema's row, and otherwise only
|
|
103
87
|
// consider same-name rows that no schema claims yet (never another schema's model).
|
|
104
|
-
const _mod_0 = await import('./index-
|
|
105
|
-
const _ns_0 = _mod_0.
|
|
88
|
+
const _mod_0 = await import('./index-C-NqjjY_.js');
|
|
89
|
+
const _ns_0 = _mod_0.bh;
|
|
106
90
|
const { modelSchemas } = _ns_0;
|
|
107
|
-
const _mod_1 = await import('./index-
|
|
108
|
-
const _ns_1 = _mod_1.
|
|
91
|
+
const _mod_1 = await import('./index-C-NqjjY_.js');
|
|
92
|
+
const _ns_1 = _mod_1.bg;
|
|
109
93
|
const { schemas: schemasTable } = _ns_1;
|
|
110
94
|
let dbModels = await db
|
|
111
95
|
.select({
|
|
@@ -252,14 +236,14 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
|
|
|
252
236
|
// Step 2: Fallback to Schema context (only if database doesn't have the model)
|
|
253
237
|
// This handles the case where model exists in schema file but not yet in database
|
|
254
238
|
try {
|
|
255
|
-
const _mod_2 = await import('./Schema-
|
|
239
|
+
const _mod_2 = await import('./Schema-COTbavcm.js');
|
|
256
240
|
const _ns_2 = _mod_2.b;
|
|
257
241
|
const schemaMod = _ns_2;
|
|
258
242
|
const { Schema } = schemaMod;
|
|
259
243
|
// Stopped meanwhile (unloaded, or evicted with its schema): don't load the schema again
|
|
260
244
|
if (isActorStopped(self))
|
|
261
245
|
return;
|
|
262
|
-
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
246
|
+
const schema = Schema.create(schemaName, { waitForReady: false, hold: false });
|
|
263
247
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
264
248
|
// Wait for schema to load if it's still loading
|
|
265
249
|
// Check if state is a loading state object (XState v5 nested states)
|
|
@@ -403,12 +387,12 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
|
|
|
403
387
|
}
|
|
404
388
|
// Also check database for models (in case they're persisted but not in Schema context)
|
|
405
389
|
if (db) {
|
|
406
|
-
const _mod_3 = await import('./index-
|
|
407
|
-
const _ns_3 = _mod_3.
|
|
390
|
+
const _mod_3 = await import('./index-C-NqjjY_.js');
|
|
391
|
+
const _ns_3 = _mod_3.bh;
|
|
408
392
|
const modelSchemaSchemaMod = _ns_3;
|
|
409
393
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
410
|
-
const _mod_4 = await import('./index-
|
|
411
|
-
const _ns_4 = _mod_4.
|
|
394
|
+
const _mod_4 = await import('./index-C-NqjjY_.js');
|
|
395
|
+
const _ns_4 = _mod_4.bg;
|
|
412
396
|
const schemaSchemaMod = _ns_4;
|
|
413
397
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
414
398
|
// Query all models for this schema to check for duplicates (case-insensitive)
|
|
@@ -503,12 +487,12 @@ const loadOrCreateModel = fromCallback(({ sendBack, input: { context }, self })
|
|
|
503
487
|
}
|
|
504
488
|
// Mark schema as draft when a new model is created so saveNewVersion() can persist it
|
|
505
489
|
try {
|
|
506
|
-
const _mod_5 = await import('./Schema-
|
|
490
|
+
const _mod_5 = await import('./Schema-COTbavcm.js');
|
|
507
491
|
const _ns_5 = _mod_5.b;
|
|
508
492
|
const schemaMod = _ns_5;
|
|
509
493
|
const { Schema } = schemaMod;
|
|
510
494
|
if (!isActorStopped(self)) {
|
|
511
|
-
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
495
|
+
const schema = Schema.create(schemaName, { waitForReady: false, hold: false });
|
|
512
496
|
schema.getService().send({ type: 'markAsDraft', propertyKey: 'schema:models' });
|
|
513
497
|
}
|
|
514
498
|
}
|
|
@@ -551,10 +535,10 @@ const validateModel = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
|
551
535
|
const _validateModel = async () => {
|
|
552
536
|
try {
|
|
553
537
|
// Use dynamic imports to break circular dependencies
|
|
554
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
538
|
+
const validationServiceMod = await import('./SchemaValidationService-paOfbcwd.js');
|
|
555
539
|
const { SchemaValidationService } = validationServiceMod;
|
|
556
540
|
const validationService = new SchemaValidationService();
|
|
557
|
-
const _mod_6 = await import('./Schema-
|
|
541
|
+
const _mod_6 = await import('./Schema-COTbavcm.js');
|
|
558
542
|
const _ns_6 = _mod_6.b;
|
|
559
543
|
const schemaMod = _ns_6;
|
|
560
544
|
const { Schema } = schemaMod;
|
|
@@ -576,9 +560,7 @@ const validateModel = fromCallback(({ sendBack, input: { context }, self }) => {
|
|
|
576
560
|
return;
|
|
577
561
|
if (context.schemaName) {
|
|
578
562
|
try {
|
|
579
|
-
const schema = Schema.create(context.schemaName, {
|
|
580
|
-
waitForReady: false,
|
|
581
|
-
});
|
|
563
|
+
const schema = Schema.create(context.schemaName, { waitForReady: false, hold: false });
|
|
582
564
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
583
565
|
const schemaStatus = schemaSnapshot.value;
|
|
584
566
|
// Only validate against schema if it's loaded (in idle state)
|
|
@@ -673,7 +655,7 @@ const createModelProperties = fromCallback(({ sendBack, input, self }) => {
|
|
|
673
655
|
return;
|
|
674
656
|
}
|
|
675
657
|
logger$5(`Creating ${Object.keys(propertyDefinitions).length} properties for model "${modelName}" (id: ${_dbId})`);
|
|
676
|
-
const mod = await import('./ModelProperty-
|
|
658
|
+
const mod = await import('./ModelProperty-C1Fzcnbm.js');
|
|
677
659
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
678
660
|
if (!ModelProperty) {
|
|
679
661
|
logger$5('ModelProperty not available from dynamic import');
|
|
@@ -698,8 +680,8 @@ const createModelProperties = fromCallback(({ sendBack, input, self }) => {
|
|
|
698
680
|
: undefined;
|
|
699
681
|
// Otherwise use provided ID or generate a random one
|
|
700
682
|
// IDs should be generated in the import process before creating properties
|
|
701
|
-
const _mod_7 = await import('./index-
|
|
702
|
-
const _ns_7 = _mod_7.
|
|
683
|
+
const _mod_7 = await import('./index-C-NqjjY_.js');
|
|
684
|
+
const _ns_7 = _mod_7.bl;
|
|
703
685
|
const { generateId } = _ns_7;
|
|
704
686
|
const propertyFileId = propData.id || propertyRecord?.schemaFileId || generateId();
|
|
705
687
|
logger$5(`Creating property "${propName}" with fileId "${propertyFileId}"`);
|
|
@@ -716,8 +698,8 @@ const createModelProperties = fromCallback(({ sendBack, input, self }) => {
|
|
|
716
698
|
}
|
|
717
699
|
else if (refModelName) {
|
|
718
700
|
// Fallback: resolve the ref by name within this model's schema
|
|
719
|
-
const _mod_8 = await import('./index-
|
|
720
|
-
const _ns_8 = _mod_8.
|
|
701
|
+
const _mod_8 = await import('./index-C-NqjjY_.js');
|
|
702
|
+
const _ns_8 = _mod_8.bi;
|
|
721
703
|
const { resolveModelRecord } = _ns_8;
|
|
722
704
|
const refModelRecord = await resolveModelRecord(refModelName, { schemaName }, db);
|
|
723
705
|
if (refModelRecord?.id) {
|
|
@@ -887,13 +869,13 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
887
869
|
const evictionEpoch = currentEvictionEpoch();
|
|
888
870
|
/** The schema to validate against; throws (validation then skips the schema check) once it was evicted. */
|
|
889
871
|
const schemaForValidation = async (schemaName) => {
|
|
890
|
-
const _mod_9 = await import('./Schema-
|
|
872
|
+
const _mod_9 = await import('./Schema-COTbavcm.js');
|
|
891
873
|
const _ns_9 = _mod_9.b;
|
|
892
874
|
const { Schema } = _ns_9;
|
|
893
875
|
if (schemaEvictedSince(schemaName, evictionEpoch)) {
|
|
894
876
|
throw new Error(`Schema "${schemaName}" was evicted during validation`);
|
|
895
877
|
}
|
|
896
|
-
return Schema.create(schemaName, { waitForReady: false });
|
|
878
|
+
return Schema.create(schemaName, { waitForReady: false, hold: false });
|
|
897
879
|
};
|
|
898
880
|
const _validate = async () => {
|
|
899
881
|
try {
|
|
@@ -905,7 +887,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
905
887
|
const structureMsg = `[validateEntity] Validating model structure`;
|
|
906
888
|
logger$4(structureMsg);
|
|
907
889
|
// Use existing Model validation
|
|
908
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
890
|
+
const validationServiceMod = await import('./SchemaValidationService-paOfbcwd.js');
|
|
909
891
|
const { SchemaValidationService } = validationServiceMod;
|
|
910
892
|
const validationService = new SchemaValidationService();
|
|
911
893
|
// Validate model structure
|
|
@@ -955,7 +937,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
955
937
|
}
|
|
956
938
|
else if (entityInput.entityType === 'modelProperty') {
|
|
957
939
|
// Use existing ModelProperty validation
|
|
958
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
940
|
+
const validationServiceMod = await import('./SchemaValidationService-paOfbcwd.js');
|
|
959
941
|
const { SchemaValidationService } = validationServiceMod;
|
|
960
942
|
const validationService = new SchemaValidationService();
|
|
961
943
|
// Validate property structure
|
|
@@ -995,7 +977,7 @@ const validateEntity = fromPromise(async ({ input }) => {
|
|
|
995
977
|
}
|
|
996
978
|
else if (entityInput.entityType === 'schema') {
|
|
997
979
|
// Schema validation - use existing validation
|
|
998
|
-
const validationServiceMod = await import('./SchemaValidationService-
|
|
980
|
+
const validationServiceMod = await import('./SchemaValidationService-paOfbcwd.js');
|
|
999
981
|
const { SchemaValidationService } = validationServiceMod;
|
|
1000
982
|
const validationService = new SchemaValidationService();
|
|
1001
983
|
const schemaResult = validationService.validateSchema(entityInput.entityData);
|
|
@@ -1083,7 +1065,7 @@ const writeToDatabase = fromCallback(({ sendBack, input }) => {
|
|
|
1083
1065
|
// initial write completes is not overwritten by the stale requestWrite payload.
|
|
1084
1066
|
let dataToWrite = input.entityData;
|
|
1085
1067
|
try {
|
|
1086
|
-
const mod = await import('./ModelProperty-
|
|
1068
|
+
const mod = await import('./ModelProperty-C1Fzcnbm.js');
|
|
1087
1069
|
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1088
1070
|
if (ModelProperty && typeof ModelProperty.getById === 'function') {
|
|
1089
1071
|
const instance = ModelProperty.getById(input.entityId);
|
|
@@ -1477,7 +1459,7 @@ const modelMachine = setup({
|
|
|
1477
1459
|
// Create ModelProperty instances for any new property IDs
|
|
1478
1460
|
if (Array.isArray(newPropertyIds) && newPropertyIds.length > 0) {
|
|
1479
1461
|
// Import and create instances asynchronously (fire-and-forget)
|
|
1480
|
-
import('./ModelProperty-
|
|
1462
|
+
import('./ModelProperty-C1Fzcnbm.js').then(({ ModelProperty }) => {
|
|
1481
1463
|
if (self.getSnapshot().status === 'stopped')
|
|
1482
1464
|
return;
|
|
1483
1465
|
const createPromises = newPropertyIds.map(async (propertyFileId) => {
|
|
@@ -1828,6 +1810,9 @@ function setupEntityLiveQuery(instance, config) {
|
|
|
1828
1810
|
logger('Instance state not found');
|
|
1829
1811
|
return;
|
|
1830
1812
|
}
|
|
1813
|
+
// Unloaded or destroyed while setup awaited: subscribing now would leak the query.
|
|
1814
|
+
if (isActorStopped(instance.getService()))
|
|
1815
|
+
return;
|
|
1831
1816
|
// Subscribe to liveQuery updates
|
|
1832
1817
|
const subscription = query$.subscribe({
|
|
1833
1818
|
next: async (rows) => {
|
|
@@ -2011,7 +1996,7 @@ const saveDraftLogger = debug('seedSdk:model:saveDraftToDb');
|
|
|
2011
1996
|
// Lazy import cache for ModelProperty to avoid circular dependency
|
|
2012
1997
|
// Eagerly start loading to minimize delay on first access
|
|
2013
1998
|
let ModelPropertyClass = null;
|
|
2014
|
-
const modelPropertyImportPromise = import('./ModelProperty-
|
|
1999
|
+
const modelPropertyImportPromise = import('./ModelProperty-C1Fzcnbm.js')
|
|
2015
2000
|
.then(module => {
|
|
2016
2001
|
ModelPropertyClass = module.ModelProperty;
|
|
2017
2002
|
return ModelPropertyClass;
|
|
@@ -2026,9 +2011,8 @@ function getModelProperty() {
|
|
|
2026
2011
|
// and the getter will return empty array, which matches the original behavior
|
|
2027
2012
|
return ModelPropertyClass;
|
|
2028
2013
|
}
|
|
2029
|
-
//
|
|
2030
|
-
|
|
2031
|
-
const modelInstanceState = new WeakMap();
|
|
2014
|
+
// Mutable state per Model instance
|
|
2015
|
+
const modelInstanceState = new ActorKeyedState();
|
|
2032
2016
|
// Settles once the properties passed to Model.create exist, or rejects when they can't be created.
|
|
2033
2017
|
// The model reaches idle before its write, so idle alone doesn't mean they exist yet. Keyed by the
|
|
2034
2018
|
// actor because callers hold the proxy, not the instance.
|
|
@@ -2228,6 +2212,7 @@ class Model {
|
|
|
2228
2212
|
}
|
|
2229
2213
|
const waitForReady = options?.waitForReady !== false;
|
|
2230
2214
|
const readyTimeout = options?.readyTimeout ?? DEFAULT_READY_TIMEOUT_MS;
|
|
2215
|
+
const holds = options?.hold === false ? 0 : 1;
|
|
2231
2216
|
// Extract schema name and instance
|
|
2232
2217
|
let schemaName;
|
|
2233
2218
|
let schemaInstance; // Using any to avoid circular dependency with Schema
|
|
@@ -2245,12 +2230,10 @@ class Model {
|
|
|
2245
2230
|
const id = options?.modelFileId || options?.id; // schemaFileId (string) - public ID
|
|
2246
2231
|
const registerWithSchema = options?.registerWithSchema !== false && schemaInstance !== undefined;
|
|
2247
2232
|
// Step 1: Check ID-based cache first (if ID provided)
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
refCount: refCount + 1,
|
|
2253
|
-
});
|
|
2233
|
+
const cachedById = id ? this.instanceCacheById.get(id) : undefined;
|
|
2234
|
+
if (cachedById) {
|
|
2235
|
+
cachedById.refCount += holds;
|
|
2236
|
+
const { instance } = cachedById;
|
|
2254
2237
|
logger(`Model.create: Found instance in ID cache for "${modelName}" (ID: ${id})`);
|
|
2255
2238
|
if (!waitForReady)
|
|
2256
2239
|
return instance;
|
|
@@ -2284,18 +2267,16 @@ class Model {
|
|
|
2284
2267
|
// create('My Model') calls get new instances with incremented names.
|
|
2285
2268
|
if (id && uniqueModelName === modelName) {
|
|
2286
2269
|
const legacyKey = `${schemaName}:${modelName}`;
|
|
2287
|
-
|
|
2288
|
-
|
|
2270
|
+
const legacyEntry = this.instanceCache.get(legacyKey);
|
|
2271
|
+
if (legacyEntry) {
|
|
2272
|
+
const { instance } = legacyEntry;
|
|
2289
2273
|
const ctx = instance._getSnapshotContext();
|
|
2290
2274
|
if (!ctx._idFromSchema && !this.isOtherModelId(ctx.id, id)) {
|
|
2291
|
-
|
|
2292
|
-
instance,
|
|
2293
|
-
refCount: refCount + 1,
|
|
2294
|
-
});
|
|
2275
|
+
legacyEntry.refCount += holds;
|
|
2295
2276
|
logger(`Model.create: Found instance in legacy cache for "${modelName}"`);
|
|
2296
2277
|
const existingId = instance._getSnapshotContext().id;
|
|
2297
2278
|
if (existingId) {
|
|
2298
|
-
this.instanceCacheById.set(existingId,
|
|
2279
|
+
this.instanceCacheById.set(existingId, legacyEntry);
|
|
2299
2280
|
this.instanceCacheByName.set(legacyKey, existingId);
|
|
2300
2281
|
}
|
|
2301
2282
|
if (!waitForReady)
|
|
@@ -2325,17 +2306,15 @@ class Model {
|
|
|
2325
2306
|
// This is a fallback in case an instance was cached with a unique name
|
|
2326
2307
|
if (this.instanceCache.has(nameKey) &&
|
|
2327
2308
|
!this.isOtherModelId(this.instanceCache.get(nameKey).instance._getSnapshotContext().id, id)) {
|
|
2328
|
-
const
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
refCount: refCount + 1,
|
|
2332
|
-
});
|
|
2309
|
+
const legacyEntry = this.instanceCache.get(nameKey);
|
|
2310
|
+
legacyEntry.refCount += holds;
|
|
2311
|
+
const { instance } = legacyEntry;
|
|
2333
2312
|
logger(`Model.create: Found instance in legacy cache for "${modelName}"`);
|
|
2334
2313
|
// Migrate to new cache structure
|
|
2335
2314
|
const context = instance._getSnapshotContext();
|
|
2336
2315
|
const existingId = context.id; // id is now the schemaFileId (string)
|
|
2337
2316
|
if (existingId) {
|
|
2338
|
-
this.instanceCacheById.set(existingId,
|
|
2317
|
+
this.instanceCacheById.set(existingId, legacyEntry);
|
|
2339
2318
|
this.instanceCacheByName.set(nameKey, existingId);
|
|
2340
2319
|
}
|
|
2341
2320
|
if (!waitForReady)
|
|
@@ -2398,168 +2377,88 @@ class Model {
|
|
|
2398
2377
|
});
|
|
2399
2378
|
}
|
|
2400
2379
|
}
|
|
2401
|
-
// Wrap instance in Proxy for reactive property access
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
const context = target._getSnapshotContext();
|
|
2412
|
-
return context.modelName;
|
|
2413
|
-
}
|
|
2414
|
-
// Handle 'id' property - returns the schemaFileId (string)
|
|
2415
|
-
if (prop === 'id') {
|
|
2416
|
-
const context = target._getSnapshotContext();
|
|
2417
|
-
return context.id; // id is now the schemaFileId (string)
|
|
2418
|
-
}
|
|
2419
|
-
// Handle tracked properties
|
|
2420
|
-
if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
|
|
2421
|
-
const context = target._getSnapshotContext();
|
|
2422
|
-
return context[prop];
|
|
2423
|
-
}
|
|
2424
|
-
// Handle 'properties' getter - not tracked, but accessible via getter
|
|
2425
|
-
if (typeof prop === 'string' && prop === 'properties') {
|
|
2426
|
-
// Delegate to the getter method on the instance
|
|
2427
|
-
return target.properties;
|
|
2428
|
-
}
|
|
2429
|
-
// For methods and other properties, use Reflect
|
|
2430
|
-
return Reflect.get(target, prop);
|
|
2431
|
-
},
|
|
2432
|
-
set(target, prop, value) {
|
|
2433
|
-
// Handle special properties
|
|
2434
|
-
if (prop === '_service') {
|
|
2435
|
-
return Reflect.set(target, prop, value);
|
|
2380
|
+
// Wrap instance in Proxy for reactive property access. `name` is an alias for `modelName`.
|
|
2381
|
+
const sendUpdate = (target, prop, value) => {
|
|
2382
|
+
if (prop === 'modelName') {
|
|
2383
|
+
// Model name change - need to update Schema and database
|
|
2384
|
+
const context = target._getSnapshotContext();
|
|
2385
|
+
const oldName = context.modelName;
|
|
2386
|
+
const newName = value;
|
|
2387
|
+
if (oldName === newName) {
|
|
2388
|
+
logger(`Model name unchanged: "${oldName}"`);
|
|
2389
|
+
return;
|
|
2436
2390
|
}
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2391
|
+
logger(`Updating model name from "${oldName}" to "${newName}"`);
|
|
2392
|
+
// Update Model instance cache using new ID-based structure
|
|
2393
|
+
const modelFileId = context.id; // id is now the schemaFileId (string)
|
|
2394
|
+
if (modelFileId) {
|
|
2395
|
+
Model.updateNameIndex(oldName, newName, context.schemaName, modelFileId);
|
|
2440
2396
|
}
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
const
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
if (oldName === newName) {
|
|
2450
|
-
logger(`Model name unchanged: "${oldName}"`);
|
|
2451
|
-
return true;
|
|
2452
|
-
}
|
|
2453
|
-
logger(`Updating model name from "${oldName}" to "${newName}"`);
|
|
2454
|
-
// Update Model instance cache using new ID-based structure
|
|
2455
|
-
const modelFileId = context.id; // id is now the schemaFileId (string)
|
|
2456
|
-
if (modelFileId) {
|
|
2457
|
-
Model.updateNameIndex(oldName, newName, context.schemaName, modelFileId);
|
|
2458
|
-
}
|
|
2459
|
-
else {
|
|
2460
|
-
// Fallback to legacy cache if no ID (shouldn't happen, but safety)
|
|
2461
|
-
const oldCacheKey = `${context.schemaName}:${oldName}`;
|
|
2462
|
-
const newCacheKey = `${context.schemaName}:${newName}`;
|
|
2463
|
-
if (Model.instanceCache.has(oldCacheKey)) {
|
|
2464
|
-
const entry = Model.instanceCache.get(oldCacheKey);
|
|
2465
|
-
Model.instanceCache.delete(oldCacheKey);
|
|
2466
|
-
Model.instanceCache.set(newCacheKey, entry);
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
// Update Model context
|
|
2470
|
-
target._service.send({
|
|
2471
|
-
type: 'updateContext',
|
|
2472
|
-
modelName: newName,
|
|
2473
|
-
});
|
|
2474
|
-
// Mark model as draft
|
|
2475
|
-
target._service.send({
|
|
2476
|
-
type: 'markAsDraft',
|
|
2477
|
-
propertyKey: 'modelName',
|
|
2478
|
-
});
|
|
2479
|
-
// Save draft to database immediately so changes persist
|
|
2480
|
-
trackDraftSave(target._service, target._saveDraftToDb(oldName, newName), `Model "${newName}"`);
|
|
2481
|
-
// NOTE: Schema is not notified of model name changes during edits.
|
|
2482
|
-
// Schema will read from Model instances when persisting/saving.
|
|
2483
|
-
}
|
|
2484
|
-
else if (prop === 'properties') {
|
|
2485
|
-
// Properties are read-only computed values from ModelProperty instances
|
|
2486
|
-
// Cannot be set directly - properties are managed via ModelProperty instances
|
|
2487
|
-
throw new Error('Cannot set model.properties directly. Properties are computed from ModelProperty instances.');
|
|
2488
|
-
}
|
|
2489
|
-
else if (prop === 'description') {
|
|
2490
|
-
// Description is not supported - JSON files can have it but we ignore it at runtime
|
|
2491
|
-
throw new Error('Cannot set model.description. Description is not supported in runtime Model instances.');
|
|
2492
|
-
}
|
|
2493
|
-
else {
|
|
2494
|
-
// Standard property update
|
|
2495
|
-
target._service.send({
|
|
2496
|
-
type: 'updateContext',
|
|
2497
|
-
[prop]: value,
|
|
2498
|
-
});
|
|
2397
|
+
else {
|
|
2398
|
+
// Fallback to legacy cache if no ID (shouldn't happen, but safety)
|
|
2399
|
+
const oldCacheKey = `${context.schemaName}:${oldName}`;
|
|
2400
|
+
const newCacheKey = `${context.schemaName}:${newName}`;
|
|
2401
|
+
if (Model.instanceCache.has(oldCacheKey)) {
|
|
2402
|
+
const entry = Model.instanceCache.get(oldCacheKey);
|
|
2403
|
+
Model.instanceCache.delete(oldCacheKey);
|
|
2404
|
+
Model.instanceCache.set(newCacheKey, entry);
|
|
2499
2405
|
}
|
|
2500
|
-
return true;
|
|
2501
2406
|
}
|
|
2502
|
-
//
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2407
|
+
// Update Model context
|
|
2408
|
+
target._service.send({
|
|
2409
|
+
type: 'updateContext',
|
|
2410
|
+
modelName: newName,
|
|
2411
|
+
});
|
|
2412
|
+
// Mark model as draft
|
|
2413
|
+
target._service.send({
|
|
2414
|
+
type: 'markAsDraft',
|
|
2415
|
+
propertyKey: 'modelName',
|
|
2416
|
+
});
|
|
2417
|
+
// Save draft to database immediately so changes persist
|
|
2418
|
+
trackDraftSave(target._service, target._saveDraftToDb(oldName, newName), `Model "${newName}"`);
|
|
2419
|
+
// NOTE: Schema is not notified of model name changes during edits.
|
|
2420
|
+
// Schema will read from Model instances when persisting/saving.
|
|
2421
|
+
}
|
|
2422
|
+
else {
|
|
2423
|
+
// Standard property update
|
|
2424
|
+
target._service.send({
|
|
2425
|
+
type: 'updateContext',
|
|
2426
|
+
[prop]: value,
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
const proxiedInstance = createReactiveProxy({
|
|
2431
|
+
instance: newInstance,
|
|
2432
|
+
service: newInstance._service,
|
|
2433
|
+
trackedProperties: TRACKED_PROPERTIES,
|
|
2434
|
+
getContext: (target) => target._getSnapshotContext(),
|
|
2435
|
+
sendUpdate,
|
|
2436
|
+
resolve: (target, prop) => {
|
|
2507
2437
|
if (prop === 'name') {
|
|
2508
|
-
return
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
return true;
|
|
2513
|
-
}
|
|
2514
|
-
// Check tracked properties
|
|
2515
|
-
if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
|
|
2516
|
-
const context = target._getSnapshotContext();
|
|
2517
|
-
return prop in context;
|
|
2438
|
+
return {
|
|
2439
|
+
get: () => target._getSnapshotContext().modelName,
|
|
2440
|
+
set: (value) => sendUpdate(target, 'modelName', value),
|
|
2441
|
+
};
|
|
2518
2442
|
}
|
|
2519
|
-
return
|
|
2443
|
+
return undefined;
|
|
2520
2444
|
},
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
additionalKeys.push('name');
|
|
2445
|
+
virtualKeys: () => ['name'],
|
|
2446
|
+
onSet: (_target, prop) => {
|
|
2447
|
+
if (prop === 'properties') {
|
|
2448
|
+
// Properties are read-only computed values from ModelProperty instances
|
|
2449
|
+
throw new Error('Cannot set model.properties directly. Properties are computed from ModelProperty instances.');
|
|
2527
2450
|
}
|
|
2528
|
-
if (
|
|
2529
|
-
|
|
2451
|
+
if (prop === 'description') {
|
|
2452
|
+
// Description is not supported - JSON files can have it but we ignore it at runtime
|
|
2453
|
+
throw new Error('Cannot set model.description. Description is not supported in runtime Model instances.');
|
|
2530
2454
|
}
|
|
2531
|
-
return additionalKeys.length > 0 ? [...keys, ...additionalKeys] : keys;
|
|
2532
|
-
},
|
|
2533
|
-
getOwnPropertyDescriptor(target, prop) {
|
|
2534
|
-
// Handle 'name' as an alias for 'modelName'
|
|
2535
|
-
if (prop === 'name') {
|
|
2536
|
-
return getInvariantSafePropertyDescriptor(target, prop, {
|
|
2537
|
-
value: target._getSnapshotContext().modelName,
|
|
2538
|
-
});
|
|
2539
|
-
}
|
|
2540
|
-
// Handle 'id' property - returns the modelFileId
|
|
2541
|
-
if (prop === 'id') {
|
|
2542
|
-
return getInvariantSafePropertyDescriptor(target, prop, {
|
|
2543
|
-
value: target._getSnapshotContext().id, // id is now the schemaFileId (string)
|
|
2544
|
-
writable: false, // id is read-only
|
|
2545
|
-
});
|
|
2546
|
-
}
|
|
2547
|
-
let invent;
|
|
2548
|
-
if (typeof prop === 'string' && TRACKED_PROPERTIES.includes(prop)) {
|
|
2549
|
-
const context = target._getSnapshotContext();
|
|
2550
|
-
if (prop in context) {
|
|
2551
|
-
invent = { value: context[prop] };
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
return getInvariantSafePropertyDescriptor(target, prop, invent);
|
|
2555
2455
|
},
|
|
2556
2456
|
});
|
|
2557
2457
|
// Step 8: Store in new ID-based cache
|
|
2558
|
-
// resolvedId is guaranteed to be defined at this point (generated if not provided)
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
});
|
|
2458
|
+
// resolvedId is guaranteed to be defined at this point (generated if not provided).
|
|
2459
|
+
// The ID and legacy caches share one entry: one hold count for the instance.
|
|
2460
|
+
const entry = { instance: proxiedInstance, refCount: holds };
|
|
2461
|
+
this.instanceCacheById.set(resolvedId, entry);
|
|
2563
2462
|
// Step 9: Store in name-based index (placeholder key when !id; loadOrCreateModel will replace with final name)
|
|
2564
2463
|
this.instanceCacheByName.set(nameKey, resolvedId);
|
|
2565
2464
|
// Step 9b: When created with id (schema model) and unique name, also register original name so create(modelName) returns same instance
|
|
@@ -2567,10 +2466,7 @@ class Model {
|
|
|
2567
2466
|
this.instanceCacheByName.set(originalNameKey, resolvedId);
|
|
2568
2467
|
}
|
|
2569
2468
|
// Step 10: Also store in legacy cache (for backward compatibility during migration)
|
|
2570
|
-
this.instanceCache.set(nameKey,
|
|
2571
|
-
instance: proxiedInstance,
|
|
2572
|
-
refCount: 1,
|
|
2573
|
-
});
|
|
2469
|
+
this.instanceCache.set(nameKey, entry);
|
|
2574
2470
|
logger(`Model.create: Created new instance for "${uniqueModelName}" (ID: ${id})`);
|
|
2575
2471
|
// Model instance is now cached and accessible via Model.getById() and Model.getByName()
|
|
2576
2472
|
// No wrapper or store registration needed
|
|
@@ -2851,42 +2747,80 @@ class Model {
|
|
|
2851
2747
|
return this.waitUntilReady(proxiedInstance, readyTimeout);
|
|
2852
2748
|
}
|
|
2853
2749
|
/**
|
|
2854
|
-
* Get Model instance by modelFileId (O(1) lookup)
|
|
2750
|
+
* Get Model instance by modelFileId (O(1) lookup). Takes a hold on the instance; release it with
|
|
2751
|
+
* `unload()`.
|
|
2855
2752
|
*/
|
|
2856
2753
|
static getById(modelFileId) {
|
|
2857
2754
|
const entry = this.instanceCacheById.get(modelFileId);
|
|
2858
|
-
if (entry)
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2755
|
+
if (!entry)
|
|
2756
|
+
return undefined;
|
|
2757
|
+
entry.refCount += 1;
|
|
2758
|
+
return entry.instance;
|
|
2759
|
+
}
|
|
2760
|
+
/**
|
|
2761
|
+
* @internal For a Schema loading its models: true when this load should take the schema's hold
|
|
2762
|
+
* on the model (pass no `hold` option), false when the schema already holds it (pass
|
|
2763
|
+
* `hold: false`). After a true, call `dropSchemaHold` if the load returns no model.
|
|
2764
|
+
*/
|
|
2765
|
+
static takeSchemaHold(modelFileId) {
|
|
2766
|
+
if (!modelFileId || this.schemaHeldModelIds.has(modelFileId))
|
|
2767
|
+
return false;
|
|
2768
|
+
this.schemaHeldModelIds.add(modelFileId);
|
|
2769
|
+
return true;
|
|
2770
|
+
}
|
|
2771
|
+
/** @internal The load `takeSchemaHold` approved found no model: there is no hold to release. */
|
|
2772
|
+
static dropSchemaHold(modelFileId) {
|
|
2773
|
+
this.schemaHeldModelIds.delete(modelFileId);
|
|
2774
|
+
}
|
|
2775
|
+
/** @internal A Schema's last unload: releases its hold on each of its models. */
|
|
2776
|
+
static releaseSchemaHolds(schemaName) {
|
|
2777
|
+
for (const modelFileId of [...this.schemaHeldModelIds]) {
|
|
2778
|
+
const model = this.peek(modelFileId);
|
|
2779
|
+
if (!model) {
|
|
2780
|
+
this.schemaHeldModelIds.delete(modelFileId);
|
|
2781
|
+
continue;
|
|
2782
|
+
}
|
|
2783
|
+
if (model._getSnapshotContext().schemaName !== schemaName)
|
|
2784
|
+
continue;
|
|
2785
|
+
this.schemaHeldModelIds.delete(modelFileId);
|
|
2786
|
+
model.unload();
|
|
2865
2787
|
}
|
|
2866
|
-
return undefined;
|
|
2867
2788
|
}
|
|
2868
2789
|
/**
|
|
2869
|
-
*
|
|
2790
|
+
* The cached Model with this modelFileId, without taking a hold. For SDK code that reads the
|
|
2791
|
+
* model and doesn't hand it to a caller; callers that keep it use `getById`, `find` or `create`.
|
|
2792
|
+
*/
|
|
2793
|
+
static peek(modelFileId) {
|
|
2794
|
+
return this.instanceCacheById.get(modelFileId)?.instance;
|
|
2795
|
+
}
|
|
2796
|
+
/**
|
|
2797
|
+
* Get Model instance by name (O(1) lookup via name→ID mapping). Takes a hold on the instance;
|
|
2798
|
+
* release it with `unload()`.
|
|
2870
2799
|
*
|
|
2871
2800
|
* @param modelName - The name of the model
|
|
2872
2801
|
* @param schemaName - The schema name (optional, will query DB if not provided)
|
|
2873
2802
|
* @returns The Model instance if found, undefined otherwise
|
|
2874
2803
|
*/
|
|
2875
2804
|
static getByName(modelName, schemaName) {
|
|
2805
|
+
const model = this.peekByName(modelName, schemaName);
|
|
2806
|
+
return model?.id ? this.getById(model.id) : undefined;
|
|
2807
|
+
}
|
|
2808
|
+
/**
|
|
2809
|
+
* `getByName` without taking a hold. Without `schemaName` it searches every cached schema and
|
|
2810
|
+
* throws AmbiguousModelError when models from several schemas share the name; callers that know
|
|
2811
|
+
* the schema or model id should use Model.resolve() instead.
|
|
2812
|
+
*/
|
|
2813
|
+
static peekByName(modelName, schemaName) {
|
|
2876
2814
|
if (schemaName) {
|
|
2877
|
-
const
|
|
2878
|
-
|
|
2879
|
-
if (!id) {
|
|
2880
|
-
return undefined;
|
|
2881
|
-
}
|
|
2882
|
-
return this.getById(id);
|
|
2815
|
+
const id = this.instanceCacheByName.get(`${schemaName}:${modelName}`);
|
|
2816
|
+
return id ? this.peek(id) : undefined;
|
|
2883
2817
|
}
|
|
2884
|
-
// If schemaName not provided, search all name keys. Model names are only unique per schema, so
|
|
2885
|
-
// this throws AmbiguousModelError when cached models from several schemas share the name.
|
|
2886
|
-
// Callers that know the schema or model id should use Model.resolve() instead.
|
|
2887
2818
|
return this._getUniqueCachedModel(modelName, (cachedModelName) => cachedModelName === modelName);
|
|
2888
2819
|
}
|
|
2889
|
-
/**
|
|
2820
|
+
/**
|
|
2821
|
+
* The one cached Model whose name matches (no hold taken), or AmbiguousModelError if models from
|
|
2822
|
+
* several schemas do.
|
|
2823
|
+
*/
|
|
2890
2824
|
static _getUniqueCachedModel(label, matches) {
|
|
2891
2825
|
const matchesById = new Map(); // modelFileId -> schemaName
|
|
2892
2826
|
for (const [nameKey, id] of this.instanceCacheByName.entries()) {
|
|
@@ -2900,32 +2834,32 @@ class Model {
|
|
|
2900
2834
|
throw new AmbiguousModelError(label, [...matchesById.values()]);
|
|
2901
2835
|
}
|
|
2902
2836
|
const [matchId] = matchesById.keys();
|
|
2903
|
-
return matchId ? this.
|
|
2837
|
+
return matchId ? this.peek(matchId) : undefined;
|
|
2904
2838
|
}
|
|
2905
2839
|
/**
|
|
2906
2840
|
* Resolve a cached Model from the most specific scope available: modelFileId (Model.id), then
|
|
2907
|
-
* schemaName + modelName, then modelName alone.
|
|
2841
|
+
* schemaName + modelName, then modelName alone. Takes no hold.
|
|
2908
2842
|
*/
|
|
2909
2843
|
static resolve(modelName, scope = {}) {
|
|
2910
2844
|
if (scope.modelFileId) {
|
|
2911
|
-
const byId = this.
|
|
2845
|
+
const byId = this.peek(scope.modelFileId);
|
|
2912
2846
|
if (byId)
|
|
2913
2847
|
return byId;
|
|
2914
2848
|
}
|
|
2915
2849
|
if (!modelName)
|
|
2916
2850
|
return undefined;
|
|
2917
2851
|
if (scope.schemaName) {
|
|
2918
|
-
const bySchema = this.
|
|
2852
|
+
const bySchema = this.peekByName(modelName, scope.schemaName);
|
|
2919
2853
|
if (bySchema)
|
|
2920
2854
|
return bySchema;
|
|
2921
2855
|
}
|
|
2922
|
-
return this.
|
|
2856
|
+
return this.peekByName(modelName);
|
|
2923
2857
|
}
|
|
2924
2858
|
/**
|
|
2925
2859
|
* Find Model by modelType (an EAS model name, as seeds.type stores it). Matched as ADR 0008
|
|
2926
2860
|
* matches EAS names: `new_model` finds "New model", and `htmlpage` (an older SDK's name) finds
|
|
2927
2861
|
* "HTMLPage", unless HTMLPage's nameMatch (ADR 0009) is `exact`. Only the tightest matching tier
|
|
2928
|
-
* counts; matches in several schemas are ambiguous.
|
|
2862
|
+
* counts; matches in several schemas are ambiguous. Takes no hold.
|
|
2929
2863
|
*/
|
|
2930
2864
|
static findByModelType(modelType) {
|
|
2931
2865
|
if (!modelType)
|
|
@@ -2937,7 +2871,7 @@ class Model {
|
|
|
2937
2871
|
return this._getUniqueCachedModel(modelType, (cachedModelName) => best.has(cachedModelName));
|
|
2938
2872
|
}
|
|
2939
2873
|
/**
|
|
2940
|
-
* Get all Model instances for a schema from cache only (synchronous).
|
|
2874
|
+
* Get all Model instances for a schema from cache only (synchronous). Takes no holds.
|
|
2941
2875
|
* Includes models created at runtime via Model.create() that may not yet be in schema context.
|
|
2942
2876
|
*/
|
|
2943
2877
|
static getCachedInstancesForSchema(schemaName) {
|
|
@@ -2946,7 +2880,7 @@ class Model {
|
|
|
2946
2880
|
for (const [nameKey, id] of this.instanceCacheByName.entries()) {
|
|
2947
2881
|
const [cachedSchemaName] = nameKey.split(':');
|
|
2948
2882
|
if (cachedSchemaName === schemaName && id && !seen.has(id)) {
|
|
2949
|
-
const instance = this.
|
|
2883
|
+
const instance = this.peek(id);
|
|
2950
2884
|
if (instance) {
|
|
2951
2885
|
instances.push(instance);
|
|
2952
2886
|
seen.add(id);
|
|
@@ -2968,16 +2902,16 @@ class Model {
|
|
|
2968
2902
|
}
|
|
2969
2903
|
/**
|
|
2970
2904
|
* Async Model.resolve(): exact cache hit by modelFileId or schemaName+modelName, else the DB row for
|
|
2971
|
-
* that scope (instantiating the Model), and only then the name-only fallback.
|
|
2905
|
+
* that scope (instantiating the Model), and only then the name-only fallback. Takes no hold.
|
|
2972
2906
|
*/
|
|
2973
2907
|
static async resolveAsync(modelName, scope = {}) {
|
|
2974
2908
|
if (scope.modelFileId) {
|
|
2975
|
-
const byId = this.
|
|
2909
|
+
const byId = this.peek(scope.modelFileId);
|
|
2976
2910
|
if (byId)
|
|
2977
2911
|
return byId;
|
|
2978
2912
|
}
|
|
2979
2913
|
if (modelName && scope.schemaName) {
|
|
2980
|
-
const bySchema = this.
|
|
2914
|
+
const bySchema = this.peekByName(modelName, scope.schemaName);
|
|
2981
2915
|
if (bySchema)
|
|
2982
2916
|
return bySchema;
|
|
2983
2917
|
}
|
|
@@ -3006,7 +2940,7 @@ class Model {
|
|
|
3006
2940
|
return undefined;
|
|
3007
2941
|
if (modelDestroyedSince(record.modelFileId, evictionEpoch))
|
|
3008
2942
|
return undefined;
|
|
3009
|
-
return this.create(record.modelName, record.schemaName, { id: record.modelFileId });
|
|
2943
|
+
return this.create(record.modelName, record.schemaName, { id: record.modelFileId, hold: false });
|
|
3010
2944
|
}
|
|
3011
2945
|
}
|
|
3012
2946
|
catch (error) {
|
|
@@ -3014,7 +2948,7 @@ class Model {
|
|
|
3014
2948
|
}
|
|
3015
2949
|
}
|
|
3016
2950
|
}
|
|
3017
|
-
return modelName ? this.getByNameAsync(modelName) : undefined;
|
|
2951
|
+
return modelName ? this.getByNameAsync(modelName, undefined, { hold: false }) : undefined;
|
|
3018
2952
|
}
|
|
3019
2953
|
/**
|
|
3020
2954
|
* Get Model instance by name, querying database if not in cache
|
|
@@ -3022,11 +2956,11 @@ class Model {
|
|
|
3022
2956
|
*
|
|
3023
2957
|
* @param modelName - The name of the model
|
|
3024
2958
|
* @param schemaName - Optional schema name (will query DB if not provided)
|
|
3025
|
-
* @returns The Model instance if found, undefined otherwise
|
|
2959
|
+
* @returns The Model instance if found, undefined otherwise. Takes a hold unless `hold: false`.
|
|
3026
2960
|
*/
|
|
3027
2961
|
static async getByNameAsync(modelName, schemaName, options) {
|
|
3028
2962
|
// First try cache
|
|
3029
|
-
const cached = this.getByName(modelName, schemaName);
|
|
2963
|
+
const cached = options?.hold === false ? this.peekByName(modelName, schemaName) : this.getByName(modelName, schemaName);
|
|
3030
2964
|
if (cached) {
|
|
3031
2965
|
return cached;
|
|
3032
2966
|
}
|
|
@@ -3039,8 +2973,8 @@ class Model {
|
|
|
3039
2973
|
const evictionEpoch = options?.evictionEpoch ?? currentEvictionEpoch();
|
|
3040
2974
|
try {
|
|
3041
2975
|
// Query model by name (throws AmbiguousModelError when several schemas define it)
|
|
3042
|
-
const _mod_10 = await import('./index-
|
|
3043
|
-
const _ns_10 = _mod_10.
|
|
2976
|
+
const _mod_10 = await import('./index-C-NqjjY_.js');
|
|
2977
|
+
const _ns_10 = _mod_10.bi;
|
|
3044
2978
|
const { resolveModelRecord } = _ns_10;
|
|
3045
2979
|
const resolved = await resolveModelRecord(modelName, {}, db);
|
|
3046
2980
|
if (!resolved?.schemaFileId) {
|
|
@@ -3074,6 +3008,7 @@ class Model {
|
|
|
3074
3008
|
// Create model instance (will be cached)
|
|
3075
3009
|
return this.create(record.modelName, record.schemaName, {
|
|
3076
3010
|
id: record.modelFileId, // id is now the schemaFileId (string)
|
|
3011
|
+
...(options?.hold === false && { hold: false }),
|
|
3077
3012
|
});
|
|
3078
3013
|
}
|
|
3079
3014
|
catch (error) {
|
|
@@ -3097,7 +3032,7 @@ class Model {
|
|
|
3097
3032
|
return undefined;
|
|
3098
3033
|
}
|
|
3099
3034
|
// Step 1: Check cache first (fast path)
|
|
3100
|
-
const cached = this.getById(modelFileId);
|
|
3035
|
+
const cached = options?.hold === false ? this.peek(modelFileId) : this.getById(modelFileId);
|
|
3101
3036
|
if (cached) {
|
|
3102
3037
|
logger(`Model.createById: Found instance in cache for ID "${modelFileId}"`);
|
|
3103
3038
|
return cached;
|
|
@@ -3146,6 +3081,7 @@ class Model {
|
|
|
3146
3081
|
logger(`Model.createById: Creating model "${modelName}" in schema "${schemaName}" from ID "${modelFileId}"`);
|
|
3147
3082
|
return this.create(modelName, schemaName, {
|
|
3148
3083
|
id: modelFileId, // id is now the schemaFileId (string)
|
|
3084
|
+
...(options?.hold === false && { hold: false }),
|
|
3149
3085
|
});
|
|
3150
3086
|
}
|
|
3151
3087
|
catch (error) {
|
|
@@ -3252,7 +3188,8 @@ class Model {
|
|
|
3252
3188
|
* Get all Model instances, optionally filtered by schema.
|
|
3253
3189
|
* When DB is available, loads from DB via getModelsData; otherwise returns from cache.
|
|
3254
3190
|
* With waitForReady, waits for each model to be ready (idle, with any properties from Model.create
|
|
3255
|
-
* created) and leaves out models that error or time out.
|
|
3191
|
+
* created) and leaves out models that error or time out. Takes no holds: a caller that keeps a
|
|
3192
|
+
* model uses `Model.find` or `Model.create`.
|
|
3256
3193
|
*/
|
|
3257
3194
|
static async all(schemaName, options) {
|
|
3258
3195
|
const { waitForReady = false, readyTimeout = DEFAULT_READY_TIMEOUT_MS } = options ?? {};
|
|
@@ -3264,7 +3201,7 @@ class Model {
|
|
|
3264
3201
|
for (const [nameKey, id] of this.instanceCacheByName.entries()) {
|
|
3265
3202
|
const [cachedSchemaName] = nameKey.split(':');
|
|
3266
3203
|
if (cachedSchemaName === schemaName) {
|
|
3267
|
-
const instance = this.
|
|
3204
|
+
const instance = this.peek(id);
|
|
3268
3205
|
if (instance && !seen.has(id)) {
|
|
3269
3206
|
instances.push(instance);
|
|
3270
3207
|
seen.add(id);
|
|
@@ -3307,7 +3244,7 @@ class Model {
|
|
|
3307
3244
|
for (const row of rows) {
|
|
3308
3245
|
// A model can appear more than once (e.g. duplicate model_schemas links); return it once.
|
|
3309
3246
|
if (row.schemaFileId && !seen.has(row.schemaFileId)) {
|
|
3310
|
-
const instance = await this.createById(row.schemaFileId);
|
|
3247
|
+
const instance = await this.createById(row.schemaFileId, { hold: false });
|
|
3311
3248
|
if (instance && !seen.has(instance.id ?? row.schemaFileId)) {
|
|
3312
3249
|
instances.push(instance);
|
|
3313
3250
|
seen.add(instance.id ?? row.schemaFileId);
|
|
@@ -3319,7 +3256,7 @@ class Model {
|
|
|
3319
3256
|
for (const [nameKey, id] of this.instanceCacheByName.entries()) {
|
|
3320
3257
|
const [cachedSchemaName] = nameKey.split(':');
|
|
3321
3258
|
if (cachedSchemaName === schemaName && id && !seen.has(id)) {
|
|
3322
|
-
const instance = this.
|
|
3259
|
+
const instance = this.peek(id);
|
|
3323
3260
|
if (instance) {
|
|
3324
3261
|
instances.push(instance);
|
|
3325
3262
|
seen.add(id);
|
|
@@ -3699,6 +3636,8 @@ class Model {
|
|
|
3699
3636
|
if (context.schemaName !== schemaName)
|
|
3700
3637
|
continue;
|
|
3701
3638
|
const nameKey = `${context.schemaName}:${context.modelName}`;
|
|
3639
|
+
if (context.id)
|
|
3640
|
+
this.schemaHeldModelIds.delete(context.id);
|
|
3702
3641
|
clearDestroySubscriptions(instance, { instanceState: modelInstanceState });
|
|
3703
3642
|
forceRemoveFromCaches(instance, {
|
|
3704
3643
|
getCacheKeys: () => (context.id ? [context.id, nameKey] : [nameKey]),
|
|
@@ -3765,6 +3704,8 @@ class Model {
|
|
|
3765
3704
|
// Before the caches are cleared, so a lookup by id already reading the row doesn't re-cache it
|
|
3766
3705
|
if (modelFileId)
|
|
3767
3706
|
recordModelDestroy(modelFileId);
|
|
3707
|
+
if (modelFileId)
|
|
3708
|
+
Model.schemaHeldModelIds.delete(modelFileId);
|
|
3768
3709
|
const cacheKeys = [];
|
|
3769
3710
|
if (modelFileId)
|
|
3770
3711
|
cacheKeys.push(modelFileId);
|
|
@@ -3792,7 +3733,7 @@ class Model {
|
|
|
3792
3733
|
.limit(1);
|
|
3793
3734
|
if (modelRecords.length > 0) {
|
|
3794
3735
|
const modelId = modelRecords[0].id;
|
|
3795
|
-
const { detachModelRows } = await import('./detachRowsBeforeDelete-
|
|
3736
|
+
const { detachModelRows } = await import('./detachRowsBeforeDelete-C1iapUFl.js');
|
|
3796
3737
|
await detachModelRows(db, [typeof modelId === 'string' ? parseInt(modelId, 10) : modelId]);
|
|
3797
3738
|
await db.delete(modelSchemas).where(eq(modelSchemas.modelId, modelId));
|
|
3798
3739
|
await db
|
|
@@ -3803,10 +3744,10 @@ class Model {
|
|
|
3803
3744
|
}
|
|
3804
3745
|
if (schemaName && modelName) {
|
|
3805
3746
|
// Imported here, not at module load: Model and Schema import each other.
|
|
3806
|
-
const _mod_11 = await import('./Schema-
|
|
3747
|
+
const _mod_11 = await import('./Schema-COTbavcm.js');
|
|
3807
3748
|
const _ns_11 = _mod_11.b;
|
|
3808
3749
|
const { Schema } = _ns_11;
|
|
3809
|
-
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
3750
|
+
const schema = Schema.create(schemaName, { waitForReady: false, hold: false });
|
|
3810
3751
|
const schemaContext = schema.getService().getSnapshot().context;
|
|
3811
3752
|
if (schemaContext.models?.[modelName]) {
|
|
3812
3753
|
const updatedModels = { ...schemaContext.models };
|
|
@@ -3847,8 +3788,8 @@ class Model {
|
|
|
3847
3788
|
return undefined;
|
|
3848
3789
|
}
|
|
3849
3790
|
// Model names are only unique per schema: find this model's row by its id (schemaFileId).
|
|
3850
|
-
const _mod_12 = await import('./index-
|
|
3851
|
-
const _ns_12 = _mod_12.
|
|
3791
|
+
const _mod_12 = await import('./index-C-NqjjY_.js');
|
|
3792
|
+
const _ns_12 = _mod_12.bi;
|
|
3852
3793
|
const { resolveModelRecord } = _ns_12;
|
|
3853
3794
|
const modelRecord = await resolveModelRecord(modelName, { modelFileId: context.id, schemaName: context.schemaName }, db);
|
|
3854
3795
|
if (!modelRecord?.id) {
|
|
@@ -4048,6 +3989,12 @@ Model.savingModels = new Set();
|
|
|
4048
3989
|
Model.cachedClientInitialized = null;
|
|
4049
3990
|
Model.clientCheckTime = 0;
|
|
4050
3991
|
Model.CLIENT_CHECK_CACHE_MS = 50; // Cache for 50ms to avoid excessive checks
|
|
3992
|
+
/**
|
|
3993
|
+
* Models their schema holds, by modelFileId. A schema's first load of a model takes one hold for
|
|
3994
|
+
* the schema, and the schema's last unload releases it (releaseSchemaHolds), so a user's unload
|
|
3995
|
+
* can't drop a model out of `schema.models` while the schema is loaded.
|
|
3996
|
+
*/
|
|
3997
|
+
Model.schemaHeldModelIds = new Set();
|
|
4051
3998
|
|
|
4052
3999
|
var Model$1 = /*#__PURE__*/Object.freeze({
|
|
4053
4000
|
__proto__: null,
|
|
@@ -4107,5 +4054,5 @@ var errors = /*#__PURE__*/Object.freeze({
|
|
|
4107
4054
|
UnknownModelError: UnknownModelError
|
|
4108
4055
|
});
|
|
4109
4056
|
|
|
4110
|
-
export { ConflictError as C, ItemCreateValidationError as I, Model as M, TModelSchema as T, UnknownModelError as U, TModelValues as a, anyEvictionSince as b, currentEvictionEpoch as c, ItemCreateError as d, setupEntityLiveQuery as e, finishSchemaDestroy as f, getDraftSaveError as g, writeToDatabase$1 as h,
|
|
4111
|
-
//# sourceMappingURL=errors-
|
|
4057
|
+
export { ConflictError as C, ItemCreateValidationError as I, Model as M, TModelSchema as T, UnknownModelError as U, TModelValues as a, anyEvictionSince as b, currentEvictionEpoch as c, ItemCreateError as d, setupEntityLiveQuery as e, finishSchemaDestroy as f, getDraftSaveError as g, writeToDatabase$1 as h, Model$1 as i, errors as j, recordSchemaDestroy as r, schemaEvictedSince as s, trackDraftSave as t, writeProcessMachine as w };
|
|
4058
|
+
//# sourceMappingURL=errors-CQagdED2.js.map
|