@seedprotocol/sdk 0.4.3 → 0.4.4

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.
Files changed (192) hide show
  1. package/dist/{ArweaveClient-BvJ1FhQ5.js → ArweaveClient-CczHvccG.js} +4 -4
  2. package/dist/{ArweaveClient-BvJ1FhQ5.js.map → ArweaveClient-CczHvccG.js.map} +1 -1
  3. package/dist/{ArweaveClient-CleX_4Gw.js → ArweaveClient-DkNLWiSZ.js} +4 -4
  4. package/dist/{ArweaveClient-CleX_4Gw.js.map → ArweaveClient-DkNLWiSZ.js.map} +1 -1
  5. package/dist/{json-I3vJhXo8.js → ClientManager-DoHUt8tU.js} +6732 -6325
  6. package/dist/ClientManager-DoHUt8tU.js.map +1 -0
  7. package/dist/{Db-BPnO1-_p.js → Db-BzQR2KX9.js} +4 -4
  8. package/dist/{Db-BPnO1-_p.js.map → Db-BzQR2KX9.js.map} +1 -1
  9. package/dist/{Db-DX08SxS9.js → Db-DJvjXVlp.js} +4 -11
  10. package/dist/{Db-DX08SxS9.js.map → Db-DJvjXVlp.js.map} +1 -1
  11. package/dist/{EasClient-BwhUcPjY.js → EasClient-CHQYmjj2.js} +3 -3
  12. package/dist/{EasClient-BwhUcPjY.js.map → EasClient-CHQYmjj2.js.map} +1 -1
  13. package/dist/{EasClient-CJSs38Db.js → EasClient-CodrIgW-.js} +3 -3
  14. package/dist/{EasClient-CJSs38Db.js.map → EasClient-CodrIgW-.js.map} +1 -1
  15. package/dist/{FileManager-Ct91ZhOE.js → FileManager-BIVsDnMu.js} +3 -3
  16. package/dist/{FileManager-Ct91ZhOE.js.map → FileManager-BIVsDnMu.js.map} +1 -1
  17. package/dist/{FileManager-B1tdLMsX.js → FileManager-BbvkZJCH.js} +3 -3
  18. package/dist/{FileManager-B1tdLMsX.js.map → FileManager-BbvkZJCH.js.map} +1 -1
  19. package/dist/Item/Item.d.ts +28 -7
  20. package/dist/Item/Item.d.ts.map +1 -1
  21. package/dist/Item/service/actors/runPublish.d.ts +5 -0
  22. package/dist/Item/service/actors/runPublish.d.ts.map +1 -0
  23. package/dist/Item/service/itemMachineSingle.d.ts +10 -5
  24. package/dist/Item/service/itemMachineSingle.d.ts.map +1 -1
  25. package/dist/ItemProperty/ItemProperty.d.ts +30 -5
  26. package/dist/ItemProperty/ItemProperty.d.ts.map +1 -1
  27. package/dist/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
  28. package/dist/ItemProperty/service/propertyMachine.d.ts +10 -10
  29. package/dist/ItemProperty/service/propertyMachine.d.ts.map +1 -1
  30. package/dist/Model/Model.d.ts +27 -20
  31. package/dist/Model/Model.d.ts.map +1 -1
  32. package/dist/Model/index.d.ts +1 -1
  33. package/dist/Model/service/actors/createModelProperties.d.ts.map +1 -1
  34. package/dist/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
  35. package/dist/Model/service/actors/validateModel.d.ts.map +1 -1
  36. package/dist/Model/service/modelMachine.d.ts +18 -3
  37. package/dist/Model/service/modelMachine.d.ts.map +1 -1
  38. package/dist/ModelProperty/ModelProperty.d.ts +25 -2
  39. package/dist/ModelProperty/ModelProperty.d.ts.map +1 -1
  40. package/dist/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
  41. package/dist/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
  42. package/dist/ModelProperty/service/modelPropertyMachine.d.ts +17 -3
  43. package/dist/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
  44. package/dist/{ModelProperty-Cr3BmgkC.js → ModelProperty-gjcA83Mq.js} +380 -113
  45. package/dist/ModelProperty-gjcA83Mq.js.map +1 -0
  46. package/dist/{PathResolver-BErmcZqP.js → PathResolver-9zAzPhee.js} +3 -3
  47. package/dist/{PathResolver-BErmcZqP.js.map → PathResolver-9zAzPhee.js.map} +1 -1
  48. package/dist/{PathResolver-DJdxE_OK.js → PathResolver-kGzba-zC.js} +3 -3
  49. package/dist/{PathResolver-DJdxE_OK.js.map → PathResolver-kGzba-zC.js.map} +1 -1
  50. package/dist/{QueryClient-DIu9c-w6.js → QueryClient-C7ZkTT0z.js} +3 -3
  51. package/dist/{QueryClient-DIu9c-w6.js.map → QueryClient-C7ZkTT0z.js.map} +1 -1
  52. package/dist/{QueryClient-D2mv63gP.js → QueryClient-CEtsek7Q.js} +3 -3
  53. package/dist/{QueryClient-D2mv63gP.js.map → QueryClient-CEtsek7Q.js.map} +1 -1
  54. package/dist/Schema/Schema.d.ts +24 -3
  55. package/dist/Schema/Schema.d.ts.map +1 -1
  56. package/dist/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
  57. package/dist/Schema/service/actors/createPropertyInstances.d.ts.map +1 -1
  58. package/dist/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
  59. package/dist/Schema/service/actors/verifyPropertyInstancesInCache.d.ts.map +1 -1
  60. package/dist/Schema/service/actors/writeModelsToDb.d.ts.map +1 -1
  61. package/dist/Schema/service/actors/writeSchemaToDb.d.ts.map +1 -1
  62. package/dist/Schema/service/addModelsMachine.d.ts.map +1 -1
  63. package/dist/Schema/service/schemaMachine.d.ts +17 -3
  64. package/dist/Schema/service/schemaMachine.d.ts.map +1 -1
  65. package/dist/{Schema-DeKabJ0T.js → Schema-ClTcpgbt.js} +272 -161
  66. package/dist/Schema-ClTcpgbt.js.map +1 -0
  67. package/dist/{SchemaValidationService-cTlURuDt.js → SchemaValidationService-BfoEiHNr.js} +3 -3
  68. package/dist/{SchemaValidationService-cTlURuDt.js.map → SchemaValidationService-BfoEiHNr.js.map} +1 -1
  69. package/dist/browser/db/Db.d.ts.map +1 -1
  70. package/dist/browser/react/SeedProvider.d.ts +30 -0
  71. package/dist/browser/react/SeedProvider.d.ts.map +1 -0
  72. package/dist/browser/react/index.d.ts +4 -1
  73. package/dist/browser/react/index.d.ts.map +1 -1
  74. package/dist/browser/react/item.d.ts +10 -6
  75. package/dist/browser/react/item.d.ts.map +1 -1
  76. package/dist/browser/react/itemProperty.d.ts +37 -1
  77. package/dist/browser/react/itemProperty.d.ts.map +1 -1
  78. package/dist/browser/react/liveQuery.d.ts.map +1 -1
  79. package/dist/browser/react/model.d.ts +21 -7
  80. package/dist/browser/react/model.d.ts.map +1 -1
  81. package/dist/browser/react/modelProperty.d.ts +23 -0
  82. package/dist/browser/react/modelProperty.d.ts.map +1 -1
  83. package/dist/browser/react/queryClient.d.ts +28 -0
  84. package/dist/browser/react/queryClient.d.ts.map +1 -0
  85. package/dist/browser/react/schema.d.ts +8 -0
  86. package/dist/browser/react/schema.d.ts.map +1 -1
  87. package/dist/browser/react/trash.d.ts +5 -2
  88. package/dist/browser/react/trash.d.ts.map +1 -1
  89. package/dist/cjs/{ModelProperty-MkN5Rmx7.js → ModelProperty-BRKRREYP.js} +387 -113
  90. package/dist/cjs/ModelProperty-BRKRREYP.js.map +1 -0
  91. package/dist/cjs/{Schema-B5cr_JVK.js → Schema-CV9hMg8m.js} +320 -209
  92. package/dist/cjs/Schema-CV9hMg8m.js.map +1 -0
  93. package/dist/cjs/{SchemaValidationService-BgIzc3-r.js → SchemaValidationService-DUtQUerg.js} +3 -3
  94. package/dist/cjs/{SchemaValidationService-BgIzc3-r.js.map → SchemaValidationService-DUtQUerg.js.map} +1 -1
  95. package/dist/cjs/{getItem-CVJJPky2.js → getItem-BThT-UOt.js} +3 -3
  96. package/dist/cjs/{getItem-CVJJPky2.js.map → getItem-BThT-UOt.js.map} +1 -1
  97. package/dist/cjs/{getPublishPayload-DbOc3WA-.js → getPublishPayload-CKZ7rVbU.js} +25 -10
  98. package/dist/cjs/getPublishPayload-CKZ7rVbU.js.map +1 -0
  99. package/dist/cjs/{getPublishUploads-NzioLz-3.js → getPublishUploads-CuGIvV-Q.js} +4 -4
  100. package/dist/cjs/getPublishUploads-CuGIvV-Q.js.map +1 -0
  101. package/dist/cjs/{getSegmentedItemProperties-BsaklLwI.js → getSegmentedItemProperties-BCJXJlTR.js} +2 -2
  102. package/dist/cjs/{getSegmentedItemProperties-BsaklLwI.js.map → getSegmentedItemProperties-BCJXJlTR.js.map} +1 -1
  103. package/dist/cjs/{index-BmIVfqGN.js → index-C3j3m34a.js} +10302 -9891
  104. package/dist/cjs/index-C3j3m34a.js.map +1 -0
  105. package/dist/cjs/{index-C_0angRB.js → index-CbTBDqTJ.js} +3 -3
  106. package/dist/cjs/index-CbTBDqTJ.js.map +1 -0
  107. package/dist/client/actors/processSchemaFiles.d.ts.map +1 -1
  108. package/dist/db/read/getItemData.d.ts.map +1 -1
  109. package/dist/db/read/getItems.d.ts.map +1 -1
  110. package/dist/db/read/getModelPropertiesData.d.ts +19 -0
  111. package/dist/db/read/getModelPropertiesData.d.ts.map +1 -0
  112. package/dist/db/read/getModelsData.d.ts +15 -0
  113. package/dist/db/read/getModelsData.d.ts.map +1 -0
  114. package/dist/db/read/getPublishPayload.d.ts.map +1 -1
  115. package/dist/db/read/getPublishUploads.d.ts +1 -7
  116. package/dist/db/read/getPublishUploads.d.ts.map +1 -1
  117. package/dist/db/read/getSchemaUidForModel.d.ts.map +1 -1
  118. package/dist/db/write/updateSeedUid.d.ts +7 -0
  119. package/dist/db/write/updateSeedUid.d.ts.map +1 -0
  120. package/dist/events/item/index.d.ts.map +1 -1
  121. package/dist/events/item/syncDbWithEas.d.ts.map +1 -1
  122. package/dist/{getItem-CcttmUY_.js → getItem-BWPo8wd0.js} +3 -3
  123. package/dist/{getItem-CcttmUY_.js.map → getItem-BWPo8wd0.js.map} +1 -1
  124. package/dist/{getPublishPayload-NFpqbd_H.js → getPublishPayload-Caw2laZM.js} +24 -9
  125. package/dist/getPublishPayload-Caw2laZM.js.map +1 -0
  126. package/dist/{getPublishUploads-Cpb9vgwE.js → getPublishUploads-MlyBuoXh.js} +4 -4
  127. package/dist/getPublishUploads-MlyBuoXh.js.map +1 -0
  128. package/dist/{getSegmentedItemProperties-DiyQPMgI.js → getSegmentedItemProperties-COLLdDo4.js} +2 -2
  129. package/dist/{getSegmentedItemProperties-DiyQPMgI.js.map → getSegmentedItemProperties-COLLdDo4.js.map} +1 -1
  130. package/dist/helpers/db.d.ts +12 -0
  131. package/dist/helpers/db.d.ts.map +1 -1
  132. package/dist/helpers/entity/entityDestroy.d.ts +41 -0
  133. package/dist/helpers/entity/entityDestroy.d.ts.map +1 -0
  134. package/dist/helpers/entity/index.d.ts +1 -0
  135. package/dist/helpers/entity/index.d.ts.map +1 -1
  136. package/dist/helpers/index.d.ts +1 -0
  137. package/dist/helpers/index.d.ts.map +1 -1
  138. package/dist/helpers/property/index.d.ts +12 -12
  139. package/dist/helpers/property/index.d.ts.map +1 -1
  140. package/dist/helpers/reactiveProxy.d.ts.map +1 -1
  141. package/dist/helpers/updateSchema.d.ts +9 -0
  142. package/dist/helpers/updateSchema.d.ts.map +1 -1
  143. package/dist/helpers/waitForEntityIdle.d.ts +2 -2
  144. package/dist/helpers/waitForEntityIdle.d.ts.map +1 -1
  145. package/dist/imports/json.d.ts.map +1 -1
  146. package/dist/{index-CRuq6HVi.js → index-B9i_mXXp.js} +4 -4
  147. package/dist/index-B9i_mXXp.js.map +1 -0
  148. package/dist/{index-r45w9hEq.js → index-D2OGsG4v.js} +2 -2
  149. package/dist/index-D2OGsG4v.js.map +1 -0
  150. package/dist/index.d.ts +3 -1
  151. package/dist/index.d.ts.map +1 -1
  152. package/dist/interfaces/IItem.d.ts +2 -0
  153. package/dist/interfaces/IItem.d.ts.map +1 -1
  154. package/dist/interfaces/IItemProperty.d.ts +1 -0
  155. package/dist/interfaces/IItemProperty.d.ts.map +1 -1
  156. package/dist/main.cjs +2 -2
  157. package/dist/main.js +996 -1030
  158. package/dist/main.js.map +1 -1
  159. package/dist/node.js +11 -11
  160. package/dist/node.js.map +1 -1
  161. package/dist/{property-Dy09KTxg.js → property-fK7tSUDX.js} +7 -5
  162. package/dist/property-fK7tSUDX.js.map +1 -0
  163. package/dist/{queries-LZYSuhtz.js → queries-DGOk16cd.js} +2 -2
  164. package/dist/{queries-LZYSuhtz.js.map → queries-DGOk16cd.js.map} +1 -1
  165. package/dist/services/write/actors/validateEntity.d.ts.map +1 -1
  166. package/dist/services/write/actors/writeToDatabase.d.ts.map +1 -1
  167. package/dist/services/write/writeProcessMachine.d.ts +1 -1
  168. package/dist/types/index.d.ts +9 -0
  169. package/dist/types/index.d.ts.map +1 -1
  170. package/dist/types/item.d.ts +12 -0
  171. package/dist/types/item.d.ts.map +1 -1
  172. package/dist/types/property.d.ts +6 -0
  173. package/dist/types/property.d.ts.map +1 -1
  174. package/dist/types/publish.d.ts +9 -0
  175. package/dist/types/publish.d.ts.map +1 -0
  176. package/package.json +7 -3
  177. package/dist/ModelProperty-Cr3BmgkC.js.map +0 -1
  178. package/dist/Schema-DeKabJ0T.js.map +0 -1
  179. package/dist/cjs/ModelProperty-MkN5Rmx7.js.map +0 -1
  180. package/dist/cjs/Schema-B5cr_JVK.js.map +0 -1
  181. package/dist/cjs/getPublishPayload-DbOc3WA-.js.map +0 -1
  182. package/dist/cjs/getPublishUploads-NzioLz-3.js.map +0 -1
  183. package/dist/cjs/index-BmIVfqGN.js.map +0 -1
  184. package/dist/cjs/index-C_0angRB.js.map +0 -1
  185. package/dist/events/item/publish.d.ts +0 -7
  186. package/dist/events/item/publish.d.ts.map +0 -1
  187. package/dist/getPublishPayload-NFpqbd_H.js.map +0 -1
  188. package/dist/getPublishUploads-Cpb9vgwE.js.map +0 -1
  189. package/dist/index-CRuq6HVi.js.map +0 -1
  190. package/dist/index-r45w9hEq.js.map +0 -1
  191. package/dist/json-I3vJhXo8.js.map +0 -1
  192. package/dist/property-Dy09KTxg.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { fromCallback, setup, assign, createActor } from 'xstate';
2
- import { p as BaseDb, W as schemas, aC as addSchemaToDb, af as generateId, aA as listCompleteSchemaFiles, s as BaseFileManager, aD as loadModelsFromDbForSchema, ad as getLatestSchemaVersion, M as Model, a2 as addModelsToDb, q as models, G as modelSchemas, r as properties, ae as writeProcessMachine, ag as createReactiveProxy, ah as findEntity, am as loadAllSchemasFromDb, aE as isInternalSchema, aF as ConflictError, aG as unloadEntity, aH as setupEntityLiveQuery } from './json-I3vJhXo8.js';
2
+ import { aG as SEED_PROTOCOL_SCHEMA_NAME, p as BaseDb, W as schemas, aH as addSchemaToDb, ag as generateId, ae as createModelsFromJson, a2 as addModelsToDb, q as models, G as modelSchemas, r as properties, aE as listCompleteSchemaFiles, s as BaseFileManager, aI as loadModelsFromDbForSchema, ad as getLatestSchemaVersion, aJ as isInternalSchema, aK as createModelFromJson, M as Model, af as writeProcessMachine, ah as waitForEntityIdle, ai as createReactiveProxy, aj as findEntity, aq as loadAllSchemasFromDb, aL as ConflictError, aM as unloadEntity, aN as clearDestroySubscriptions, ak as forceRemoveFromCaches, al as runDestroyLifecycle, aO as setupEntityLiveQuery } from './ClientManager-DoHUt8tU.js';
3
3
  import { eq, desc, and } from 'drizzle-orm';
4
4
  import debug from 'debug';
5
- import { SchemaValidationService } from './SchemaValidationService-cTlURuDt.js';
6
- import { M as ModelProperty, c as convertPropertyToSchemaUpdate, u as updateModelProperties } from './ModelProperty-Cr3BmgkC.js';
5
+ import { SchemaValidationService } from './SchemaValidationService-BfoEiHNr.js';
6
+ import { M as ModelProperty, c as convertPropertyToSchemaUpdate, w as writeFullSchemaNewVersion, u as updateModelProperties } from './ModelProperty-gjcA83Mq.js';
7
7
  import 'pluralize';
8
8
  import 'rxjs';
9
9
  import 'lodash-es';
@@ -12,9 +12,9 @@ import '@sinclair/typebox';
12
12
  import 'arweave';
13
13
  import 'eventemitter3';
14
14
  import 'drizzle-orm/sqlite-core';
15
- import 'ethers';
16
15
  import 'nanoid';
17
16
  import 'nanoid-dictionary';
17
+ import 'ethers';
18
18
  import '@sinclair/typebox/value';
19
19
  import 'reflect-metadata';
20
20
 
@@ -32,13 +32,12 @@ const getModelIdsForSchema$1 = async (schemaId) => {
32
32
  return [];
33
33
  }
34
34
  try {
35
- const { modelSchemas, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
36
35
  const modelRecords = await db
37
36
  .select({
38
- modelFileId: modelsTable.schemaFileId,
37
+ modelFileId: models.schemaFileId,
39
38
  })
40
39
  .from(modelSchemas)
41
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
40
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
42
41
  .where(eq(modelSchemas.schemaId, schemaId));
43
42
  const modelIds = modelRecords
44
43
  .map((row) => row.modelFileId)
@@ -61,7 +60,7 @@ const createModelInstances$2 = async (modelIds) => {
61
60
  return;
62
61
  }
63
62
  try {
64
- const { Model } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aS; });
63
+ const { Model } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aX; });
65
64
  // Create instances for all model IDs in parallel
66
65
  // Model.createById() will check cache first, then query DB and create if needed
67
66
  const createPromises = modelIds.map(async (modelFileId) => {
@@ -101,13 +100,11 @@ const verifyPropertiesPersisted = async (modelId, modelName, maxRetries = 10, re
101
100
  if (!db) {
102
101
  throw new Error('Database not available for property verification');
103
102
  }
104
- const { properties: propertiesTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
105
- const { eq } = await import('drizzle-orm');
106
103
  for (let attempt = 0; attempt < maxRetries; attempt++) {
107
104
  const props = await db
108
105
  .select()
109
- .from(propertiesTable)
110
- .where(eq(propertiesTable.modelId, modelId))
106
+ .from(properties)
107
+ .where(eq(properties.modelId, modelId))
111
108
  .limit(1);
112
109
  if (props.length > 0) {
113
110
  logger$c(`Verified properties exist for model "${modelName}" (modelId: ${modelId}) after ${attempt + 1} attempt(s)`);
@@ -169,15 +166,14 @@ const getSchemaFilePath$1 = (name, version, schemaFileId) => {
169
166
  const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
170
167
  const _loadOrCreateSchema = async () => {
171
168
  const { schemaName } = context;
172
- // Check if this is an internal SDK schema (should not create files in app directory)
173
- const { isInternalSchema, SEED_PROTOCOL_SCHEMA_NAME } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aQ; });
169
+ // Check if this is an internal SDK schema (should not create files in app directory) — use static import so consumer bundles resolve correctly
174
170
  const isInternal = isInternalSchema(schemaName);
175
171
  if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
176
172
  // For Seed Protocol, always load from internal file, never create new
177
173
  logger$c(`Loading internal Seed Protocol schema from SDK`);
178
174
  console.log('[loadOrCreateSchema] Loading internal Seed Protocol schema from SDK');
179
175
  try {
180
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
176
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
181
177
  const schemaFile = internalSchema.default;
182
178
  console.log('[loadOrCreateSchema] Loaded schema file, models count:', Object.keys(schemaFile.models || {}).length);
183
179
  // Check if it exists in database, if not, add it
@@ -202,8 +198,6 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
202
198
  logger$c(`Added Seed Protocol schema to database`);
203
199
  // Also add models and properties to database
204
200
  // Convert to JsonImportSchema format for processing
205
- const { createModelsFromJson } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
206
- const { addModelsToDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aR; });
207
201
  const importData = {
208
202
  name: schemaName,
209
203
  models: Object.fromEntries(Object.entries(schemaFile.models || {}).map(([modelName, model]) => [
@@ -292,15 +286,13 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
292
286
  logger$c(`Added ${Object.keys(modelDefinitions).length} models and their properties to database for Seed Protocol schema`);
293
287
  // Verify properties are persisted (important for browser environments)
294
288
  // Query the database to get model IDs that were just created
295
- const { modelSchemas } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aO; });
296
- const { models: modelsTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
297
289
  const modelLinks = await db
298
290
  .select({
299
291
  modelId: modelSchemas.modelId,
300
- modelName: modelsTable.name,
292
+ modelName: models.name,
301
293
  })
302
294
  .from(modelSchemas)
303
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
295
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
304
296
  .where(eq(modelSchemas.schemaId, schemaRecord.id));
305
297
  // Verify properties for at least one model (Seed model if available)
306
298
  const seedModelLink = modelLinks.find((link) => link.modelName === 'Seed');
@@ -317,17 +309,14 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
317
309
  // Schema exists, but always ensure models/properties are in database
318
310
  // This handles the case where schema was added but models weren't (from previous code)
319
311
  // or where models were added but properties weren't
320
- const { modelSchemas } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aO; });
321
- const { models: modelsTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
322
- const { properties: propertiesTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
323
312
  // Check if models are linked to the schema
324
313
  const modelLinks = await db
325
314
  .select({
326
315
  modelId: modelSchemas.modelId,
327
- modelName: modelsTable.name,
316
+ modelName: models.name,
328
317
  })
329
318
  .from(modelSchemas)
330
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
319
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
331
320
  .where(eq(modelSchemas.schemaId, schemaRecord.id));
332
321
  // Check if we have all expected models
333
322
  const expectedModelNames = Object.keys(schemaFile.models || {});
@@ -343,8 +332,8 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
343
332
  if (link.modelId) {
344
333
  const props = await db
345
334
  .select()
346
- .from(propertiesTable)
347
- .where(eq(propertiesTable.modelId, link.modelId))
335
+ .from(properties)
336
+ .where(eq(properties.modelId, link.modelId))
348
337
  .limit(1);
349
338
  if (props.length === 0) {
350
339
  missingProperties = true;
@@ -358,8 +347,6 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
358
347
  if (missingModels.length > 0 || missingProperties || modelLinks.length === 0) {
359
348
  logger$c(`Seed Protocol schema exists but models/properties incomplete (missing models: ${missingModels.length}, missing properties: ${missingProperties}), adding them now`);
360
349
  console.log(`[loadOrCreateSchema] Adding models/properties: missingModels=${missingModels.length}, missingProperties=${missingProperties}, modelLinks=${modelLinks.length}`);
361
- const { createModelsFromJson } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
362
- const { addModelsToDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aR; });
363
350
  // Convert SchemaFileFormat to JsonImportSchema format
364
351
  // Schema format: { dataType, ref, refValueType, storageType, localStorageDir, filenameSuffix }
365
352
  // JSON import format: { type, model, items, storage: { type, path, extension } }
@@ -463,10 +450,10 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
463
450
  updatedModelLinks = await db
464
451
  .select({
465
452
  modelId: modelSchemas.modelId,
466
- modelName: modelsTable.name,
453
+ modelName: models.name,
467
454
  })
468
455
  .from(modelSchemas)
469
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
456
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
470
457
  .where(eq(modelSchemas.schemaId, schemaRecord.id));
471
458
  const linkedModelNames = updatedModelLinks
472
459
  .map((link) => link.modelName)
@@ -686,7 +673,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
686
673
  // Ensure models are populated (fallback for seed-protocol if missing)
687
674
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
688
675
  try {
689
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
676
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
690
677
  const internalSchemaFile = internalSchema.default;
691
678
  mergedModels = { ...(internalSchemaFile.models || {}) };
692
679
  logger$c(`Populated models for seed-protocol schema from internal file`);
@@ -881,7 +868,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
881
868
  // Ensure models are populated (fallback for seed-protocol if missing)
882
869
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
883
870
  try {
884
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
871
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
885
872
  const internalSchemaFile = internalSchema.default;
886
873
  mergedModels = { ...(internalSchemaFile.models || {}) };
887
874
  logger$c(`Populated models for seed-protocol schema from internal file`);
@@ -953,7 +940,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
953
940
  // Ensure models are populated (fallback for seed-protocol if missing)
954
941
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
955
942
  try {
956
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
943
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
957
944
  const internalSchemaFile = internalSchema.default;
958
945
  mergedModels = { ...(internalSchemaFile.models || {}) };
959
946
  logger$c(`Populated models for seed-protocol schema from internal file`);
@@ -1022,7 +1009,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
1022
1009
  // If schemaData is missing, try to load from internal schema file for seed-protocol
1023
1010
  if (!dbSchema.schemaData && schemaName === 'Seed Protocol') {
1024
1011
  try {
1025
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
1012
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
1026
1013
  const schemaFile = internalSchema.default;
1027
1014
  logger$c(`Found seed-protocol schema in internal file (schemaData missing, using internal schema)`);
1028
1015
  // Update database with schemaData for future loads
@@ -1131,7 +1118,7 @@ const loadOrCreateSchema = fromCallback(({ sendBack, input: { context } }) => {
1131
1118
  // Ensure models are populated (fallback for seed-protocol if missing)
1132
1119
  if ((!mergedModels || Object.keys(mergedModels).length === 0) && schemaName === 'Seed Protocol') {
1133
1120
  try {
1134
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
1121
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
1135
1122
  const internalSchemaFile = internalSchema.default;
1136
1123
  mergedModels = { ...(internalSchemaFile.models || {}) };
1137
1124
  logger$c(`Populated models for seed-protocol schema from internal file`);
@@ -1448,14 +1435,16 @@ const addModelsMachine = setup({
1448
1435
  createModelInstances: fromCallback(({ sendBack, input }) => {
1449
1436
  const _createInstances = async () => {
1450
1437
  const { Schema } = await Promise.resolve().then(function () { return Schema$1; });
1451
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
1452
- const { models: modelsTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
1438
+ const { BaseDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aP; });
1439
+ const { models: modelsTable } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aQ; });
1453
1440
  const { eq } = await import('drizzle-orm');
1454
- const { generateId } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aL; });
1441
+ const { generateId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aS; });
1455
1442
  const debug = (await import('debug')).default;
1456
1443
  const logger = debug('seedSdk:schema:addModels:createInstances');
1457
1444
  const schemaName = input.schemaContext.metadata?.name || input.schemaContext.schemaName;
1458
- const schemaInstance = Schema.create(schemaName);
1445
+ const schemaInstance = Schema.create(schemaName, {
1446
+ waitForReady: false,
1447
+ });
1459
1448
  const modelInstances = new Map();
1460
1449
  // Get instance state to store model instances
1461
1450
  const { schemaInstanceState } = await Promise.resolve().then(function () { return Schema$1; });
@@ -1492,7 +1481,10 @@ const addModelsMachine = setup({
1492
1481
  }
1493
1482
  // Create new Model instance with modelFileId
1494
1483
  // Model.create() will set _modelFileId in the context automatically
1495
- const modelInstance = Model.create(modelName, schemaName, { modelFileId });
1484
+ const modelInstance = Model.create(modelName, schemaName, {
1485
+ modelFileId,
1486
+ waitForReady: false,
1487
+ });
1496
1488
  const service = modelInstance.getService();
1497
1489
  logger(`Created Model instance for "${modelName}" with modelFileId "${modelFileId}"`);
1498
1490
  // Wait for the Model service to finish loading (loadOrCreateModel completes)
@@ -1673,10 +1665,8 @@ const addModelsMachine = setup({
1673
1665
  const _persist = async () => {
1674
1666
  const debug = (await import('debug')).default;
1675
1667
  const logger = debug('seedSdk:schema:addModels:persist');
1676
- const { createModelFromJson } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
1677
- const { addModelsToDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aR; });
1678
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
1679
- const { schemas: schemasTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aN; });
1668
+ const { BaseDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aP; });
1669
+ const { schemas: schemasTable } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aU; });
1680
1670
  const { eq } = await import('drizzle-orm');
1681
1671
  // Only process in browser environment where store is available
1682
1672
  if (typeof window === 'undefined') {
@@ -1991,13 +1981,12 @@ const getModelIdsForSchema = async (schemaId) => {
1991
1981
  return [];
1992
1982
  }
1993
1983
  try {
1994
- const { modelSchemas, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
1995
1984
  const modelRecords = await db
1996
1985
  .select({
1997
- modelFileId: modelsTable.schemaFileId,
1986
+ modelFileId: models.schemaFileId,
1998
1987
  })
1999
1988
  .from(modelSchemas)
2000
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
1989
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
2001
1990
  .where(eq(modelSchemas.schemaId, schemaId));
2002
1991
  const modelIds = modelRecords
2003
1992
  .map((row) => row.modelFileId)
@@ -2035,7 +2024,12 @@ const createModelInstances$1 = async (modelIds) => {
2035
2024
  return;
2036
2025
  }
2037
2026
  try {
2038
- const { Model } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aS; });
2027
+ const mod = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aX; });
2028
+ const Model = mod?.Model ?? mod?.default;
2029
+ if (!Model) {
2030
+ logger$b('Model not available from dynamic import');
2031
+ return;
2032
+ }
2039
2033
  const createPromises = modelIds.map(async (modelFileId) => {
2040
2034
  try {
2041
2035
  const model = await Model.createById(modelFileId);
@@ -2070,13 +2064,12 @@ const checkExistingSchema = fromCallback(({ sendBack, input: { context } }) => {
2070
2064
  });
2071
2065
  return;
2072
2066
  }
2073
- // Check if this is an internal SDK schema (Seed Protocol)
2074
- const { isInternalSchema, SEED_PROTOCOL_SCHEMA_NAME } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aQ; });
2067
+ // Check if this is an internal SDK schema (Seed Protocol) — use static import so consumer bundles resolve correctly
2075
2068
  const isInternal = isInternalSchema(schemaName);
2076
2069
  if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
2077
2070
  // For Seed Protocol, check if it exists in database
2078
2071
  try {
2079
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
2072
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
2080
2073
  const schemaFile = internalSchema.default;
2081
2074
  if (db && schemaFile.id) {
2082
2075
  const existing = await db
@@ -2427,15 +2420,14 @@ const writeSchemaToDb = fromCallback(({ sendBack, input }) => {
2427
2420
  const _write = async () => {
2428
2421
  const { schemaName, schemaFile, existingDbSchema } = input;
2429
2422
  try {
2430
- // Check if this is an internal SDK schema (Seed Protocol)
2431
- const { isInternalSchema, SEED_PROTOCOL_SCHEMA_NAME } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aQ; });
2423
+ // Check if this is an internal SDK schema (Seed Protocol) — use static import so consumer bundles resolve correctly
2432
2424
  const isInternal = isInternalSchema(schemaName);
2433
2425
  let finalSchema;
2434
2426
  let schemaRecord;
2435
2427
  if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
2436
2428
  // For Seed Protocol, load from internal file
2437
2429
  logger$a(`Loading internal Seed Protocol schema from SDK`);
2438
- const internalSchema = await import('./json-I3vJhXo8.js').then(function (n) { return n.aU; });
2430
+ const internalSchema = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aZ; });
2439
2431
  finalSchema = internalSchema.default;
2440
2432
  const db = BaseDb.getAppDb();
2441
2433
  if (db && finalSchema.id) {
@@ -2631,10 +2623,6 @@ const writeModelsToDb = fromCallback(({ sendBack, input }) => {
2631
2623
  const { schema, schemaRecord, schemaName } = input;
2632
2624
  try {
2633
2625
  // Check if models already exist in database
2634
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
2635
- const { modelSchemas } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aO; });
2636
- const { models: modelsTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
2637
- const { eq } = await import('drizzle-orm');
2638
2626
  const db = BaseDb.getAppDb();
2639
2627
  if (!db) {
2640
2628
  throw new Error('Database not available');
@@ -2643,10 +2631,10 @@ const writeModelsToDb = fromCallback(({ sendBack, input }) => {
2643
2631
  const modelLinks = await db
2644
2632
  .select({
2645
2633
  modelId: modelSchemas.modelId,
2646
- modelName: modelsTable.name,
2634
+ modelName: models.name,
2647
2635
  })
2648
2636
  .from(modelSchemas)
2649
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
2637
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
2650
2638
  .where(eq(modelSchemas.schemaId, schemaRecord.id));
2651
2639
  // Check if we have all expected models
2652
2640
  const expectedModelNames = Object.keys(schema.models || {});
@@ -2662,9 +2650,9 @@ const writeModelsToDb = fromCallback(({ sendBack, input }) => {
2662
2650
  for (const link of modelLinks) {
2663
2651
  if (link.modelId) {
2664
2652
  const modelRecord = await db
2665
- .select({ schemaFileId: modelsTable.schemaFileId })
2666
- .from(modelsTable)
2667
- .where(eq(modelsTable.id, link.modelId))
2653
+ .select({ schemaFileId: models.schemaFileId })
2654
+ .from(models)
2655
+ .where(eq(models.id, link.modelId))
2668
2656
  .limit(1);
2669
2657
  if (modelRecord.length > 0 && modelRecord[0].schemaFileId) {
2670
2658
  modelFileIds.push(modelRecord[0].schemaFileId);
@@ -2677,10 +2665,7 @@ const writeModelsToDb = fromCallback(({ sendBack, input }) => {
2677
2665
  });
2678
2666
  return;
2679
2667
  }
2680
- // Convert SchemaFileFormat to JsonImportSchema format
2681
- const { createModelsFromJson } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
2682
- // Check if this is Seed Protocol schema (has different format)
2683
- const { isInternalSchema, SEED_PROTOCOL_SCHEMA_NAME } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aQ; });
2668
+ // Check if this is Seed Protocol schema (has different format) — use static import so consumer bundles resolve correctly
2684
2669
  const isInternal = isInternalSchema(schemaName);
2685
2670
  let importData;
2686
2671
  if (isInternal && schemaName === SEED_PROTOCOL_SCHEMA_NAME) {
@@ -2910,7 +2895,7 @@ const createModelInstances = fromCallback(({ sendBack, input }) => {
2910
2895
  return;
2911
2896
  }
2912
2897
  try {
2913
- const { Model } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aS; });
2898
+ const { Model } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aX; });
2914
2899
  // Create instances for all model IDs in parallel
2915
2900
  // Model.createById() will check cache first, then query DB and create if needed
2916
2901
  const createPromises = modelIds.map(async (modelFileId) => {
@@ -2995,7 +2980,7 @@ const verifyModelInstancesInCache = fromCallback(({ sendBack, input }) => {
2995
2980
  }
2996
2981
  try {
2997
2982
  const result = await verifyWithRetry$2(async () => {
2998
- const { Model } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aS; });
2983
+ const { Model } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aX; });
2999
2984
  // Check each model ID in the cache
3000
2985
  const verifiedInstances = [];
3001
2986
  const missingIds = [];
@@ -3051,8 +3036,8 @@ const writePropertiesToDb = fromCallback(({ sendBack, input }) => {
3051
3036
  const _write = async () => {
3052
3037
  const { modelIds } = input;
3053
3038
  try {
3054
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
3055
- const { models: modelsTable, properties: propertiesTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aJ; });
3039
+ const { BaseDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aP; });
3040
+ const { models: modelsTable, properties: propertiesTable } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aQ; });
3056
3041
  const { eq } = await import('drizzle-orm');
3057
3042
  const db = BaseDb.getAppDb();
3058
3043
  if (!db) {
@@ -3238,8 +3223,15 @@ const createPropertyInstances = fromCallback(({ sendBack, input }) => {
3238
3223
  return;
3239
3224
  }
3240
3225
  try {
3241
- const { ModelProperty } = await import('./ModelProperty-Cr3BmgkC.js').then(function (n) { return n.b; });
3242
- const { Model } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aS; });
3226
+ const modProp = await import('./ModelProperty-gjcA83Mq.js').then(function (n) { return n.b; });
3227
+ const ModelProperty = modProp?.ModelProperty ?? modProp?.default;
3228
+ const modModel = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aX; });
3229
+ const Model = modModel?.Model ?? modModel?.default;
3230
+ if (!ModelProperty || !Model) {
3231
+ logger$2('ModelProperty or Model not available from dynamic import');
3232
+ sendBack({ type: 'instancesCreated', count: 0 });
3233
+ return;
3234
+ }
3243
3235
  // Properties are typically loaded when Model instances are loaded
3244
3236
  // But we can verify they exist by checking Model instances
3245
3237
  let successCount = 0;
@@ -3338,7 +3330,11 @@ const verifyPropertyInstancesInCache = fromCallback(({ sendBack, input }) => {
3338
3330
  }
3339
3331
  try {
3340
3332
  const result = await verifyWithRetry(async () => {
3341
- const { ModelProperty } = await import('./ModelProperty-Cr3BmgkC.js').then(function (n) { return n.b; });
3333
+ const mod = await import('./ModelProperty-gjcA83Mq.js').then(function (n) { return n.b; });
3334
+ const ModelProperty = mod?.ModelProperty ?? mod?.default;
3335
+ if (!ModelProperty) {
3336
+ throw new Error('ModelProperty not available from dynamic import');
3337
+ }
3342
3338
  // Check each property ID in the cache
3343
3339
  const verifiedInstances = [];
3344
3340
  const missingIds = [];
@@ -3498,6 +3494,23 @@ const schemaMachine = setup({
3498
3494
  return newContext;
3499
3495
  }),
3500
3496
  },
3497
+ destroyStarted: {
3498
+ actions: assign({ _destroyInProgress: true, _destroyError: null }),
3499
+ },
3500
+ destroyDone: {
3501
+ actions: assign({ _destroyInProgress: false }),
3502
+ },
3503
+ destroyError: {
3504
+ actions: assign(({ event }) => ({
3505
+ _destroyInProgress: false,
3506
+ _destroyError: event.error instanceof Error
3507
+ ? { message: event.error.message, name: event.error.name }
3508
+ : { message: String(event.error) },
3509
+ })),
3510
+ },
3511
+ clearDestroyError: {
3512
+ actions: assign({ _destroyError: null }),
3513
+ },
3501
3514
  },
3502
3515
  states: {
3503
3516
  loading: {
@@ -4091,10 +4104,12 @@ class Schema {
4091
4104
  });
4092
4105
  // Note: Property getters/setters are now handled by the Proxy in create()
4093
4106
  }
4094
- static create(schemaName) {
4107
+ static create(schemaName, options) {
4095
4108
  if (!schemaName) {
4096
4109
  throw new Error('Schema name is required');
4097
4110
  }
4111
+ const waitForReady = options?.waitForReady !== false;
4112
+ const readyTimeout = options?.readyTimeout ?? 5000;
4098
4113
  // First, check if we have an instance cached by name
4099
4114
  if (this.instanceCacheByName.has(schemaName)) {
4100
4115
  const { instance, refCount } = this.instanceCacheByName.get(schemaName);
@@ -4102,7 +4117,9 @@ class Schema {
4102
4117
  instance,
4103
4118
  refCount: refCount + 1,
4104
4119
  });
4105
- return instance;
4120
+ if (!waitForReady)
4121
+ return instance;
4122
+ return waitForEntityIdle(instance, { timeout: readyTimeout }).then(() => instance);
4106
4123
  }
4107
4124
  // Create new instance
4108
4125
  const newInstance = new this(schemaName);
@@ -4425,9 +4442,10 @@ class Schema {
4425
4442
  instance: proxiedInstance,
4426
4443
  refCount: 1,
4427
4444
  });
4428
- // The proxiedInstance is Proxied<Schema> which preserves all methods
4429
- // TypeScript recognizes this as Schema with all methods intact
4430
- return proxiedInstance;
4445
+ const schema = proxiedInstance;
4446
+ if (!waitForReady)
4447
+ return schema;
4448
+ return waitForEntityIdle(schema, { timeout: readyTimeout }).then(() => schema);
4431
4449
  }
4432
4450
  /**
4433
4451
  * Update the cache to use schemaFileId as the key instead of schemaName
@@ -4464,7 +4482,7 @@ class Schema {
4464
4482
  });
4465
4483
  return instance;
4466
4484
  }
4467
- return undefined;
4485
+ return null;
4468
4486
  }
4469
4487
  /**
4470
4488
  * Clear all cached Schema instances.
@@ -4511,17 +4529,15 @@ class Schema {
4511
4529
  return cachedInstance;
4512
4530
  }
4513
4531
  // Query database to get schema name from ID
4514
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
4515
- const { schemas: schemasTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aN; });
4516
4532
  const db = BaseDb.getAppDb();
4517
4533
  if (!db) {
4518
4534
  throw new Error('Database not available');
4519
4535
  }
4520
4536
  const dbSchemas = await db
4521
4537
  .select()
4522
- .from(schemasTable)
4523
- .where(eq(schemasTable.schemaFileId, schemaFileId))
4524
- .orderBy(desc(schemasTable.version))
4538
+ .from(schemas)
4539
+ .where(eq(schemas.schemaFileId, schemaFileId))
4540
+ .orderBy(desc(schemas.version))
4525
4541
  .limit(1);
4526
4542
  if (dbSchemas.length === 0) {
4527
4543
  throw new Error(`Schema with ID "${schemaFileId}" not found in database`);
@@ -4568,7 +4584,7 @@ class Schema {
4568
4584
  * @returns Array of Schema instances
4569
4585
  */
4570
4586
  static async all(options = {}) {
4571
- const { includeAllVersions = false, includeInternal = false } = options;
4587
+ const { includeAllVersions = false, includeInternal = false, waitForReady = false, readyTimeout = 5000, } = options;
4572
4588
  try {
4573
4589
  // Use loadAllSchemasFromDb as single source of truth
4574
4590
  // This intelligently merges database and file data, including drafts
@@ -4651,13 +4667,18 @@ class Schema {
4651
4667
  }
4652
4668
  catch (error) {
4653
4669
  // Fallback to creating by name if createById fails
4654
- schemaInstances.push(this.create(schemaName));
4670
+ schemaInstances.push(this.create(schemaName, { waitForReady: false }));
4655
4671
  }
4656
4672
  }
4657
4673
  else {
4658
- schemaInstances.push(this.create(schemaName));
4674
+ schemaInstances.push(this.create(schemaName, { waitForReady: false }));
4659
4675
  }
4660
4676
  }
4677
+ if (waitForReady && schemaInstances.length > 0) {
4678
+ await Promise.all(schemaInstances.map((s) => waitForEntityIdle(s, {
4679
+ timeout: readyTimeout,
4680
+ })));
4681
+ }
4661
4682
  return schemaInstances;
4662
4683
  }
4663
4684
  catch (error) {
@@ -4695,7 +4716,12 @@ class Schema {
4695
4716
  // Create Schema instances for each unique schema name
4696
4717
  const schemaInstances = [];
4697
4718
  for (const schemaName of uniqueSchemaNames) {
4698
- schemaInstances.push(this.create(schemaName));
4719
+ schemaInstances.push(this.create(schemaName, { waitForReady: false }));
4720
+ }
4721
+ if (waitForReady && schemaInstances.length > 0) {
4722
+ await Promise.all(schemaInstances.map((s) => waitForEntityIdle(s, {
4723
+ timeout: readyTimeout,
4724
+ })));
4699
4725
  }
4700
4726
  return schemaInstances;
4701
4727
  }
@@ -4738,6 +4764,7 @@ class Schema {
4738
4764
  */
4739
4765
  get models() {
4740
4766
  const context = this._getSnapshotContext();
4767
+ const schemaName = context.schemaName;
4741
4768
  // Get model IDs from service context (reactive state)
4742
4769
  const liveQueryIds = context._liveQueryModelIds || [];
4743
4770
  // Get pending model IDs (not yet in DB)
@@ -4746,15 +4773,27 @@ class Schema {
4746
4773
  const pendingIds = [];
4747
4774
  // Combine and deduplicate
4748
4775
  const allModelIds = [...new Set([...liveQueryIds, ...pendingIds])];
4749
- // Get Model instances from static cache
4776
+ // Get Model instances from static cache (from schema load)
4777
+ const seen = new Set();
4750
4778
  const modelInstances = [];
4751
4779
  for (const modelFileId of allModelIds) {
4752
4780
  const model = Model.getById(modelFileId);
4753
- if (model) {
4781
+ if (model && modelFileId && !seen.has(modelFileId)) {
4754
4782
  modelInstances.push(model);
4783
+ seen.add(modelFileId);
4784
+ }
4785
+ }
4786
+ // Include models created at runtime via Model.create() that belong to this schema
4787
+ // (they may not be in _liveQueryModelIds until schema context is updated)
4788
+ if (schemaName) {
4789
+ const cachedForSchema = Model.getCachedInstancesForSchema(schemaName);
4790
+ for (const model of cachedForSchema) {
4791
+ const id = model.id;
4792
+ if (id && !seen.has(id)) {
4793
+ modelInstances.push(model);
4794
+ seen.add(id);
4795
+ }
4755
4796
  }
4756
- // Note: Cannot create models asynchronously in this synchronous getter
4757
- // Models will be created elsewhere when needed
4758
4797
  }
4759
4798
  // Return a new array reference (snapshot at time of access)
4760
4799
  return [...modelInstances];
@@ -4871,9 +4910,7 @@ class Schema {
4871
4910
  throw new ConflictError(errorMessage, conflictCheck);
4872
4911
  }
4873
4912
  const context = this._getSnapshotContext();
4874
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
4875
- const { schemas: schemasTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aN; });
4876
- const { addSchemaToDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aR; });
4913
+ const { addSchemaToDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
4877
4914
  if (!context._isDraft || !context._editedProperties || context._editedProperties.size === 0) {
4878
4915
  logger('No changes to save');
4879
4916
  return '';
@@ -4913,6 +4950,11 @@ class Schema {
4913
4950
  createdAt: new Date(currentSchema.metadata.createdAt).getTime(),
4914
4951
  updatedAt: new Date(currentSchema.metadata.updatedAt).getTime(),
4915
4952
  }, currentSchema.id, JSON.stringify(currentSchema, null, 2), true);
4953
+ const dbSchema = await db
4954
+ .select()
4955
+ .from(schemas)
4956
+ .where(eq(schemas.name, this.schemaName))
4957
+ .limit(1);
4916
4958
  // Collect all edited properties and convert them to SchemaPropertyUpdate format
4917
4959
  const propertyUpdates = [];
4918
4960
  for (const propertyKey of context._editedProperties) {
@@ -4941,6 +4983,32 @@ class Schema {
4941
4983
  propertyUpdates.push(propertyUpdate);
4942
4984
  }
4943
4985
  if (propertyUpdates.length === 0) {
4986
+ // When only new models were added, _editedProperties contains 'schema:models' and we write the full schema
4987
+ if (context._editedProperties.has('schema:models')) {
4988
+ const newFilePath = await writeFullSchemaNewVersion(this.schemaName, currentSchema);
4989
+ const { BaseFileManager } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aR; });
4990
+ const fileContent = await BaseFileManager.readFileAsString(newFilePath);
4991
+ const publishedSchema = JSON.parse(fileContent);
4992
+ if (dbSchema.length > 0) {
4993
+ await db
4994
+ .update(schemas)
4995
+ .set({
4996
+ isDraft: false,
4997
+ isEdited: false,
4998
+ schemaFileId: publishedSchema.id,
4999
+ schemaData: JSON.stringify(publishedSchema, null, 2),
5000
+ version: publishedSchema.version,
5001
+ updatedAt: new Date(publishedSchema.metadata.updatedAt).getTime(),
5002
+ })
5003
+ .where(eq(schemas.id, dbSchema[0].id));
5004
+ }
5005
+ this._service.send({
5006
+ type: 'clearDraft',
5007
+ _dbUpdatedAt: new Date(publishedSchema.metadata.updatedAt).getTime(),
5008
+ _dbVersion: publishedSchema.version,
5009
+ });
5010
+ return newFilePath;
5011
+ }
4944
5012
  logger('No valid property updates to save');
4945
5013
  return '';
4946
5014
  }
@@ -4948,18 +5016,13 @@ class Schema {
4948
5016
  const newFilePath = await updateModelProperties(this.schemaName, propertyUpdates);
4949
5017
  // STEP 3: After file is written, update database to mark as published (isDraft = false)
4950
5018
  // Load the file to get the final schema with IDs
4951
- const { BaseFileManager } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aK; });
5019
+ const { BaseFileManager } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aR; });
4952
5020
  const fileContent = await BaseFileManager.readFileAsString(newFilePath);
4953
5021
  const publishedSchema = JSON.parse(fileContent);
4954
5022
  // Update database record: set isDraft = false and update schemaFileId
4955
- const dbSchema = await db
4956
- .select()
4957
- .from(schemasTable)
4958
- .where(eq(schemasTable.name, this.schemaName))
4959
- .limit(1);
4960
5023
  if (dbSchema.length > 0) {
4961
5024
  await db
4962
- .update(schemasTable)
5025
+ .update(schemas)
4963
5026
  .set({
4964
5027
  isDraft: false,
4965
5028
  isEdited: false, // Clear isEdited flag after saving to file
@@ -4968,7 +5031,7 @@ class Schema {
4968
5031
  version: publishedSchema.version,
4969
5032
  updatedAt: new Date(publishedSchema.metadata.updatedAt).getTime(),
4970
5033
  })
4971
- .where(eq(schemasTable.id, dbSchema[0].id));
5034
+ .where(eq(schemas.id, dbSchema[0].id));
4972
5035
  }
4973
5036
  else {
4974
5037
  // Create new record if it doesn't exist (shouldn't happen, but safety)
@@ -4987,7 +5050,6 @@ class Schema {
4987
5050
  _dbVersion: publishedSchema.version,
4988
5051
  });
4989
5052
  // Clear edited flags on all ModelProperty instances and in database
4990
- const { properties: propertiesTable, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
4991
5053
  for (const propertyKey of context._editedProperties) {
4992
5054
  const [modelName, propertyName] = propertyKey.split(':');
4993
5055
  const cacheKey = `${modelName}:${propertyName}`;
@@ -5005,23 +5067,23 @@ class Schema {
5005
5067
  if (db && modelName && propertyName) {
5006
5068
  // Find model by name
5007
5069
  const modelRecords = await db
5008
- .select({ id: modelsTable.id })
5009
- .from(modelsTable)
5010
- .where(eq(modelsTable.name, modelName))
5070
+ .select({ id: models.id })
5071
+ .from(models)
5072
+ .where(eq(models.name, modelName))
5011
5073
  .limit(1);
5012
5074
  if (modelRecords.length > 0) {
5013
5075
  // Find property by name and modelId
5014
5076
  const propertyRecords = await db
5015
- .select({ id: propertiesTable.id })
5016
- .from(propertiesTable)
5017
- .where(and(eq(propertiesTable.name, propertyName), eq(propertiesTable.modelId, modelRecords[0].id)))
5077
+ .select({ id: properties.id })
5078
+ .from(properties)
5079
+ .where(and(eq(properties.name, propertyName), eq(properties.modelId, modelRecords[0].id)))
5018
5080
  .limit(1);
5019
5081
  if (propertyRecords.length > 0) {
5020
5082
  // Clear isEdited flag in database
5021
5083
  await db
5022
- .update(propertiesTable)
5084
+ .update(properties)
5023
5085
  .set({ isEdited: false })
5024
- .where(eq(propertiesTable.id, propertyRecords[0].id));
5086
+ .where(eq(properties.id, propertyRecords[0].id));
5025
5087
  }
5026
5088
  }
5027
5089
  }
@@ -5035,19 +5097,18 @@ class Schema {
5035
5097
  try {
5036
5098
  if (db && context._dbId) {
5037
5099
  // Get all models for this schema
5038
- const { modelSchemas, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
5039
5100
  const modelRecords = await db
5040
- .select({ id: modelsTable.id })
5101
+ .select({ id: models.id })
5041
5102
  .from(modelSchemas)
5042
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
5103
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
5043
5104
  .where(eq(modelSchemas.schemaId, context._dbId));
5044
5105
  // Clear isEdited flag for all models
5045
5106
  for (const modelRecord of modelRecords) {
5046
5107
  if (modelRecord.id) {
5047
5108
  await db
5048
- .update(modelsTable)
5109
+ .update(models)
5049
5110
  .set({ isEdited: false })
5050
- .where(eq(modelsTable.id, modelRecord.id));
5111
+ .where(eq(models.id, modelRecord.id));
5051
5112
  }
5052
5113
  }
5053
5114
  }
@@ -5151,8 +5212,8 @@ class Schema {
5151
5212
  if (shouldRecheck) {
5152
5213
  try {
5153
5214
  // Use dynamic import for browser compatibility (require() doesn't work in browsers)
5154
- const { getClient } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aV; });
5155
- const { ClientManagerState } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aM; });
5215
+ const { getClient } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.a_; });
5216
+ const { ClientManagerState } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aT; });
5156
5217
  const client = getClient();
5157
5218
  const clientSnapshot = client.getService().getSnapshot();
5158
5219
  // Check if state is IDLE (primary check) - isInitialized is set in entry action so should be true
@@ -5223,10 +5284,8 @@ class Schema {
5223
5284
  _editedProperties: new Set(),
5224
5285
  };
5225
5286
  }
5226
- const { addSchemaToDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aR; });
5227
- const { generateId } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aL; });
5228
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
5229
- const { schemas: schemasTable } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aN; });
5287
+ const { addSchemaToDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
5288
+ const { generateId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aS; });
5230
5289
  const db = BaseDb.getAppDb();
5231
5290
  if (!db) {
5232
5291
  throw new Error('Database not found');
@@ -5246,8 +5305,8 @@ class Schema {
5246
5305
  logger(`Looking up schema by schemaFileId: ${context.id}`);
5247
5306
  const schemasById = await db
5248
5307
  .select()
5249
- .from(schemasTable)
5250
- .where(eq(schemasTable.schemaFileId, context.id)) // id is now the schemaFileId (string)
5308
+ .from(schemas)
5309
+ .where(eq(schemas.schemaFileId, context.id)) // id is now the schemaFileId (string)
5251
5310
  .limit(1);
5252
5311
  if (schemasById.length > 0) {
5253
5312
  const foundRecord = schemasById[0];
@@ -5267,8 +5326,8 @@ class Schema {
5267
5326
  logger(`Looking up schema by name "${lookupName}" (oldName: ${oldName}, finalNewName: ${finalNewName})`);
5268
5327
  const existingSchemas = await db
5269
5328
  .select()
5270
- .from(schemasTable)
5271
- .where(eq(schemasTable.name, lookupName))
5329
+ .from(schemas)
5330
+ .where(eq(schemas.name, lookupName))
5272
5331
  .limit(10); // Get multiple to find drafts
5273
5332
  logger(`Found ${existingSchemas.length} records with name "${lookupName}"`);
5274
5333
  // If name changed, prefer draft records; otherwise prefer any record
@@ -5358,14 +5417,14 @@ class Schema {
5358
5417
  saveDraftLogger(`Setting schemaFileId to ${finalSchemaFileId} (was null)`);
5359
5418
  }
5360
5419
  await db
5361
- .update(schemasTable)
5420
+ .update(schemas)
5362
5421
  .set(updateData)
5363
- .where(eq(schemasTable.id, existingSchemaRecord.id));
5422
+ .where(eq(schemas.id, existingSchemaRecord.id));
5364
5423
  // Verify what was saved by reading it back
5365
5424
  const verifyRecord = await db
5366
5425
  .select()
5367
- .from(schemasTable)
5368
- .where(eq(schemasTable.id, existingSchemaRecord.id))
5426
+ .from(schemas)
5427
+ .where(eq(schemas.id, existingSchemaRecord.id))
5369
5428
  .limit(1);
5370
5429
  if (verifyRecord.length > 0 && verifyRecord[0].schemaData) {
5371
5430
  try {
@@ -5375,15 +5434,15 @@ class Schema {
5375
5434
  saveDraftLogger(`ERROR: isDraft is not true after save! Expected true, got ${verifyRecord[0].isDraft}. This will cause the schema to load from file instead of database!`);
5376
5435
  // Try to fix it immediately
5377
5436
  await db
5378
- .update(schemasTable)
5437
+ .update(schemas)
5379
5438
  .set({ isDraft: true })
5380
- .where(eq(schemasTable.id, existingSchemaRecord.id));
5439
+ .where(eq(schemas.id, existingSchemaRecord.id));
5381
5440
  saveDraftLogger(`Attempted to fix isDraft by setting it to true again`);
5382
5441
  // Verify the fix
5383
5442
  const fixedRecord = await db
5384
5443
  .select()
5385
- .from(schemasTable)
5386
- .where(eq(schemasTable.id, existingSchemaRecord.id))
5444
+ .from(schemas)
5445
+ .where(eq(schemas.id, existingSchemaRecord.id))
5387
5446
  .limit(1);
5388
5447
  if (fixedRecord.length > 0) {
5389
5448
  saveDraftLogger(`After fix attempt: isDraft=${fixedRecord[0].isDraft}`);
@@ -5425,8 +5484,8 @@ class Schema {
5425
5484
  // Try to find by looking for ANY draft with the old name (even if it doesn't match exactly)
5426
5485
  const allDrafts = await db
5427
5486
  .select()
5428
- .from(schemasTable)
5429
- .where(eq(schemasTable.name, oldName))
5487
+ .from(schemas)
5488
+ .where(eq(schemas.name, oldName))
5430
5489
  .limit(1);
5431
5490
  if (allDrafts.length > 0 && allDrafts[0].id) {
5432
5491
  const foundRecord = allDrafts[0];
@@ -5434,7 +5493,7 @@ class Schema {
5434
5493
  // Update the existing record with the new name
5435
5494
  // CRITICAL: Ensure schemaFileId matches schema.id
5436
5495
  await db
5437
- .update(schemasTable)
5496
+ .update(schemas)
5438
5497
  .set({
5439
5498
  name: finalNewName,
5440
5499
  schemaData: JSON.stringify(currentSchema, null, 2),
@@ -5443,7 +5502,7 @@ class Schema {
5443
5502
  updatedAt: new Date(currentSchema.metadata.updatedAt).getTime(),
5444
5503
  isDraft: true, // Ensure it's marked as a draft when saving via _saveDraftToDb
5445
5504
  })
5446
- .where(eq(schemasTable.id, foundRecord.id));
5505
+ .where(eq(schemas.id, foundRecord.id));
5447
5506
  // Update context with id (schemaFileId) and conflict detection metadata
5448
5507
  try {
5449
5508
  const snapshot = this._service.getSnapshot();
@@ -5554,6 +5613,68 @@ class Schema {
5554
5613
  }
5555
5614
  }
5556
5615
  }
5616
+ /**
5617
+ * Destroy the schema instance completely: remove from caches, delete from database (cascade),
5618
+ * and stop the service. Uses shared destroy helpers.
5619
+ */
5620
+ async destroy() {
5621
+ const context = this._getSnapshotContext();
5622
+ const schemaFileId = context.id;
5623
+ const schemaName = context.schemaName;
5624
+ clearDestroySubscriptions(this, {
5625
+ instanceState: schemaInstanceState,
5626
+ onUnload: () => schemaInstanceState.delete(this),
5627
+ });
5628
+ const cacheKeys = [];
5629
+ if (schemaFileId)
5630
+ cacheKeys.push(schemaFileId);
5631
+ if (schemaName)
5632
+ cacheKeys.push(schemaName);
5633
+ forceRemoveFromCaches(this, {
5634
+ getCacheKeys: () => cacheKeys,
5635
+ caches: [
5636
+ Schema.instanceCacheById,
5637
+ Schema.instanceCacheByName,
5638
+ ],
5639
+ });
5640
+ await runDestroyLifecycle(this, {
5641
+ getService: (instance) => instance._service,
5642
+ doDestroy: async () => {
5643
+ const db = BaseDb.getAppDb();
5644
+ if (!db || !schemaFileId)
5645
+ return;
5646
+ const schemaRecords = await db
5647
+ .select({ id: schemas.id })
5648
+ .from(schemas)
5649
+ .where(eq(schemas.schemaFileId, schemaFileId));
5650
+ if (schemaRecords.length === 0)
5651
+ return;
5652
+ const schemaIds = schemaRecords
5653
+ .map((r) => r.id)
5654
+ .filter((id) => id != null);
5655
+ if (schemaIds.length === 0)
5656
+ return;
5657
+ const { inArray } = await import('drizzle-orm');
5658
+ const joinRows = await db
5659
+ .select({ modelId: modelSchemas.modelId })
5660
+ .from(modelSchemas)
5661
+ .where(inArray(modelSchemas.schemaId, schemaIds));
5662
+ const modelIds = [
5663
+ ...new Set(joinRows
5664
+ .map((r) => r.modelId)
5665
+ .filter((id) => id != null)),
5666
+ ];
5667
+ await db.delete(modelSchemas).where(inArray(modelSchemas.schemaId, schemaIds));
5668
+ for (const modelId of modelIds) {
5669
+ await db.delete(properties).where(eq(properties.modelId, modelId));
5670
+ }
5671
+ for (const modelId of modelIds) {
5672
+ await db.delete(models).where(eq(models.id, modelId));
5673
+ }
5674
+ await db.delete(schemas).where(eq(schemas.schemaFileId, schemaFileId));
5675
+ },
5676
+ });
5677
+ }
5557
5678
  /**
5558
5679
  * Set up liveQuery subscription to watch for model changes in the database
5559
5680
  * This enables cross-instance synchronization (e.g., changes in other tabs/windows)
@@ -5565,9 +5686,6 @@ class Schema {
5565
5686
  }
5566
5687
  setupEntityLiveQuery(this, {
5567
5688
  getEntityId: async (schema) => {
5568
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
5569
- const { schemas: schemasTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
5570
- const { eq } = await import('drizzle-orm');
5571
5689
  const db = BaseDb.getAppDb();
5572
5690
  if (!db) {
5573
5691
  return undefined;
@@ -5579,8 +5697,8 @@ class Schema {
5579
5697
  }
5580
5698
  const schemaRecords = await db
5581
5699
  .select()
5582
- .from(schemasTable)
5583
- .where(eq(schemasTable.name, schemaName))
5700
+ .from(schemas)
5701
+ .where(eq(schemas.name, schemaName))
5584
5702
  .limit(1);
5585
5703
  if (schemaRecords.length === 0 || !schemaRecords[0].id) {
5586
5704
  return undefined;
@@ -5588,9 +5706,6 @@ class Schema {
5588
5706
  return schemaRecords[0].id;
5589
5707
  },
5590
5708
  buildQuery: async (schemaId) => {
5591
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
5592
- const { modelSchemas, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
5593
- const { eq } = await import('drizzle-orm');
5594
5709
  const db = BaseDb.getAppDb();
5595
5710
  if (!db) {
5596
5711
  throw new Error('Database not available');
@@ -5598,11 +5713,11 @@ class Schema {
5598
5713
  return BaseDb.liveQuery(db
5599
5714
  .select({
5600
5715
  modelId: modelSchemas.modelId,
5601
- modelName: modelsTable.name,
5602
- modelFileId: modelsTable.schemaFileId,
5716
+ modelName: models.name,
5717
+ modelFileId: models.schemaFileId,
5603
5718
  })
5604
5719
  .from(modelSchemas)
5605
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
5720
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
5606
5721
  .where(eq(modelSchemas.schemaId, typeof schemaId === 'string' ? parseInt(schemaId, 10) : schemaId)));
5607
5722
  },
5608
5723
  extractEntityIds: (rows) => rows.map(row => row.modelFileId).filter(Boolean),
@@ -5662,15 +5777,11 @@ class Schema {
5662
5777
  }
5663
5778
  },
5664
5779
  createChildInstances: async (ids) => {
5665
- const { Model } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aS; });
5666
5780
  for (const id of ids) {
5667
5781
  await Model.createById(id);
5668
5782
  }
5669
5783
  },
5670
5784
  queryInitialData: async (schemaId) => {
5671
- const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
5672
- const { modelSchemas, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
5673
- const { eq } = await import('drizzle-orm');
5674
5785
  const db = BaseDb.getAppDb();
5675
5786
  if (!db) {
5676
5787
  return [];
@@ -5681,11 +5792,11 @@ class Schema {
5681
5792
  const initialModels = await db
5682
5793
  .select({
5683
5794
  modelId: modelSchemas.modelId,
5684
- modelName: modelsTable.name,
5685
- modelFileId: modelsTable.schemaFileId,
5795
+ modelName: models.name,
5796
+ modelFileId: models.schemaFileId,
5686
5797
  })
5687
5798
  .from(modelSchemas)
5688
- .innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
5799
+ .innerJoin(models, eq(modelSchemas.modelId, models.id))
5689
5800
  .where(eq(modelSchemas.schemaId, typeof schemaId === 'string' ? parseInt(schemaId, 10) : schemaId));
5690
5801
  logger(`[Schema._setupLiveQuerySubscription] Initial query found ${initialModels.length} models`);
5691
5802
  if (initialModels.length > 0) {
@@ -5742,4 +5853,4 @@ var Schema$1 = /*#__PURE__*/Object.freeze({
5742
5853
  });
5743
5854
 
5744
5855
  export { Schema, schemaInstanceState };
5745
- //# sourceMappingURL=Schema-DeKabJ0T.js.map
5856
+ //# sourceMappingURL=Schema-ClTcpgbt.js.map