@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.
- package/dist/{ArweaveClient-BvJ1FhQ5.js → ArweaveClient-CczHvccG.js} +4 -4
- package/dist/{ArweaveClient-BvJ1FhQ5.js.map → ArweaveClient-CczHvccG.js.map} +1 -1
- package/dist/{ArweaveClient-CleX_4Gw.js → ArweaveClient-DkNLWiSZ.js} +4 -4
- package/dist/{ArweaveClient-CleX_4Gw.js.map → ArweaveClient-DkNLWiSZ.js.map} +1 -1
- package/dist/{json-I3vJhXo8.js → ClientManager-DoHUt8tU.js} +6732 -6325
- package/dist/ClientManager-DoHUt8tU.js.map +1 -0
- package/dist/{Db-BPnO1-_p.js → Db-BzQR2KX9.js} +4 -4
- package/dist/{Db-BPnO1-_p.js.map → Db-BzQR2KX9.js.map} +1 -1
- package/dist/{Db-DX08SxS9.js → Db-DJvjXVlp.js} +4 -11
- package/dist/{Db-DX08SxS9.js.map → Db-DJvjXVlp.js.map} +1 -1
- package/dist/{EasClient-BwhUcPjY.js → EasClient-CHQYmjj2.js} +3 -3
- package/dist/{EasClient-BwhUcPjY.js.map → EasClient-CHQYmjj2.js.map} +1 -1
- package/dist/{EasClient-CJSs38Db.js → EasClient-CodrIgW-.js} +3 -3
- package/dist/{EasClient-CJSs38Db.js.map → EasClient-CodrIgW-.js.map} +1 -1
- package/dist/{FileManager-Ct91ZhOE.js → FileManager-BIVsDnMu.js} +3 -3
- package/dist/{FileManager-Ct91ZhOE.js.map → FileManager-BIVsDnMu.js.map} +1 -1
- package/dist/{FileManager-B1tdLMsX.js → FileManager-BbvkZJCH.js} +3 -3
- package/dist/{FileManager-B1tdLMsX.js.map → FileManager-BbvkZJCH.js.map} +1 -1
- package/dist/Item/Item.d.ts +28 -7
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/service/actors/runPublish.d.ts +5 -0
- package/dist/Item/service/actors/runPublish.d.ts.map +1 -0
- package/dist/Item/service/itemMachineSingle.d.ts +10 -5
- package/dist/Item/service/itemMachineSingle.d.ts.map +1 -1
- package/dist/ItemProperty/ItemProperty.d.ts +30 -5
- package/dist/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
- package/dist/ItemProperty/service/propertyMachine.d.ts +10 -10
- package/dist/ItemProperty/service/propertyMachine.d.ts.map +1 -1
- package/dist/Model/Model.d.ts +27 -20
- package/dist/Model/Model.d.ts.map +1 -1
- package/dist/Model/index.d.ts +1 -1
- package/dist/Model/service/actors/createModelProperties.d.ts.map +1 -1
- package/dist/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
- package/dist/Model/service/actors/validateModel.d.ts.map +1 -1
- package/dist/Model/service/modelMachine.d.ts +18 -3
- package/dist/Model/service/modelMachine.d.ts.map +1 -1
- package/dist/ModelProperty/ModelProperty.d.ts +25 -2
- package/dist/ModelProperty/ModelProperty.d.ts.map +1 -1
- package/dist/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
- package/dist/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
- package/dist/ModelProperty/service/modelPropertyMachine.d.ts +17 -3
- package/dist/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
- package/dist/{ModelProperty-Cr3BmgkC.js → ModelProperty-gjcA83Mq.js} +380 -113
- package/dist/ModelProperty-gjcA83Mq.js.map +1 -0
- package/dist/{PathResolver-BErmcZqP.js → PathResolver-9zAzPhee.js} +3 -3
- package/dist/{PathResolver-BErmcZqP.js.map → PathResolver-9zAzPhee.js.map} +1 -1
- package/dist/{PathResolver-DJdxE_OK.js → PathResolver-kGzba-zC.js} +3 -3
- package/dist/{PathResolver-DJdxE_OK.js.map → PathResolver-kGzba-zC.js.map} +1 -1
- package/dist/{QueryClient-DIu9c-w6.js → QueryClient-C7ZkTT0z.js} +3 -3
- package/dist/{QueryClient-DIu9c-w6.js.map → QueryClient-C7ZkTT0z.js.map} +1 -1
- package/dist/{QueryClient-D2mv63gP.js → QueryClient-CEtsek7Q.js} +3 -3
- package/dist/{QueryClient-D2mv63gP.js.map → QueryClient-CEtsek7Q.js.map} +1 -1
- package/dist/Schema/Schema.d.ts +24 -3
- package/dist/Schema/Schema.d.ts.map +1 -1
- package/dist/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
- package/dist/Schema/service/actors/createPropertyInstances.d.ts.map +1 -1
- package/dist/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
- package/dist/Schema/service/actors/verifyPropertyInstancesInCache.d.ts.map +1 -1
- package/dist/Schema/service/actors/writeModelsToDb.d.ts.map +1 -1
- package/dist/Schema/service/actors/writeSchemaToDb.d.ts.map +1 -1
- package/dist/Schema/service/addModelsMachine.d.ts.map +1 -1
- package/dist/Schema/service/schemaMachine.d.ts +17 -3
- package/dist/Schema/service/schemaMachine.d.ts.map +1 -1
- package/dist/{Schema-DeKabJ0T.js → Schema-ClTcpgbt.js} +272 -161
- package/dist/Schema-ClTcpgbt.js.map +1 -0
- package/dist/{SchemaValidationService-cTlURuDt.js → SchemaValidationService-BfoEiHNr.js} +3 -3
- package/dist/{SchemaValidationService-cTlURuDt.js.map → SchemaValidationService-BfoEiHNr.js.map} +1 -1
- package/dist/browser/db/Db.d.ts.map +1 -1
- package/dist/browser/react/SeedProvider.d.ts +30 -0
- package/dist/browser/react/SeedProvider.d.ts.map +1 -0
- package/dist/browser/react/index.d.ts +4 -1
- package/dist/browser/react/index.d.ts.map +1 -1
- package/dist/browser/react/item.d.ts +10 -6
- package/dist/browser/react/item.d.ts.map +1 -1
- package/dist/browser/react/itemProperty.d.ts +37 -1
- package/dist/browser/react/itemProperty.d.ts.map +1 -1
- package/dist/browser/react/liveQuery.d.ts.map +1 -1
- package/dist/browser/react/model.d.ts +21 -7
- package/dist/browser/react/model.d.ts.map +1 -1
- package/dist/browser/react/modelProperty.d.ts +23 -0
- package/dist/browser/react/modelProperty.d.ts.map +1 -1
- package/dist/browser/react/queryClient.d.ts +28 -0
- package/dist/browser/react/queryClient.d.ts.map +1 -0
- package/dist/browser/react/schema.d.ts +8 -0
- package/dist/browser/react/schema.d.ts.map +1 -1
- package/dist/browser/react/trash.d.ts +5 -2
- package/dist/browser/react/trash.d.ts.map +1 -1
- package/dist/cjs/{ModelProperty-MkN5Rmx7.js → ModelProperty-BRKRREYP.js} +387 -113
- package/dist/cjs/ModelProperty-BRKRREYP.js.map +1 -0
- package/dist/cjs/{Schema-B5cr_JVK.js → Schema-CV9hMg8m.js} +320 -209
- package/dist/cjs/Schema-CV9hMg8m.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-BgIzc3-r.js → SchemaValidationService-DUtQUerg.js} +3 -3
- package/dist/cjs/{SchemaValidationService-BgIzc3-r.js.map → SchemaValidationService-DUtQUerg.js.map} +1 -1
- package/dist/cjs/{getItem-CVJJPky2.js → getItem-BThT-UOt.js} +3 -3
- package/dist/cjs/{getItem-CVJJPky2.js.map → getItem-BThT-UOt.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-DbOc3WA-.js → getPublishPayload-CKZ7rVbU.js} +25 -10
- package/dist/cjs/getPublishPayload-CKZ7rVbU.js.map +1 -0
- package/dist/cjs/{getPublishUploads-NzioLz-3.js → getPublishUploads-CuGIvV-Q.js} +4 -4
- package/dist/cjs/getPublishUploads-CuGIvV-Q.js.map +1 -0
- package/dist/cjs/{getSegmentedItemProperties-BsaklLwI.js → getSegmentedItemProperties-BCJXJlTR.js} +2 -2
- package/dist/cjs/{getSegmentedItemProperties-BsaklLwI.js.map → getSegmentedItemProperties-BCJXJlTR.js.map} +1 -1
- package/dist/cjs/{index-BmIVfqGN.js → index-C3j3m34a.js} +10302 -9891
- package/dist/cjs/index-C3j3m34a.js.map +1 -0
- package/dist/cjs/{index-C_0angRB.js → index-CbTBDqTJ.js} +3 -3
- package/dist/cjs/index-CbTBDqTJ.js.map +1 -0
- package/dist/client/actors/processSchemaFiles.d.ts.map +1 -1
- package/dist/db/read/getItemData.d.ts.map +1 -1
- package/dist/db/read/getItems.d.ts.map +1 -1
- package/dist/db/read/getModelPropertiesData.d.ts +19 -0
- package/dist/db/read/getModelPropertiesData.d.ts.map +1 -0
- package/dist/db/read/getModelsData.d.ts +15 -0
- package/dist/db/read/getModelsData.d.ts.map +1 -0
- package/dist/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/db/read/getPublishUploads.d.ts +1 -7
- package/dist/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/db/read/getSchemaUidForModel.d.ts.map +1 -1
- package/dist/db/write/updateSeedUid.d.ts +7 -0
- package/dist/db/write/updateSeedUid.d.ts.map +1 -0
- package/dist/events/item/index.d.ts.map +1 -1
- package/dist/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/{getItem-CcttmUY_.js → getItem-BWPo8wd0.js} +3 -3
- package/dist/{getItem-CcttmUY_.js.map → getItem-BWPo8wd0.js.map} +1 -1
- package/dist/{getPublishPayload-NFpqbd_H.js → getPublishPayload-Caw2laZM.js} +24 -9
- package/dist/getPublishPayload-Caw2laZM.js.map +1 -0
- package/dist/{getPublishUploads-Cpb9vgwE.js → getPublishUploads-MlyBuoXh.js} +4 -4
- package/dist/getPublishUploads-MlyBuoXh.js.map +1 -0
- package/dist/{getSegmentedItemProperties-DiyQPMgI.js → getSegmentedItemProperties-COLLdDo4.js} +2 -2
- package/dist/{getSegmentedItemProperties-DiyQPMgI.js.map → getSegmentedItemProperties-COLLdDo4.js.map} +1 -1
- package/dist/helpers/db.d.ts +12 -0
- package/dist/helpers/db.d.ts.map +1 -1
- package/dist/helpers/entity/entityDestroy.d.ts +41 -0
- package/dist/helpers/entity/entityDestroy.d.ts.map +1 -0
- package/dist/helpers/entity/index.d.ts +1 -0
- package/dist/helpers/entity/index.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/property/index.d.ts +12 -12
- package/dist/helpers/property/index.d.ts.map +1 -1
- package/dist/helpers/reactiveProxy.d.ts.map +1 -1
- package/dist/helpers/updateSchema.d.ts +9 -0
- package/dist/helpers/updateSchema.d.ts.map +1 -1
- package/dist/helpers/waitForEntityIdle.d.ts +2 -2
- package/dist/helpers/waitForEntityIdle.d.ts.map +1 -1
- package/dist/imports/json.d.ts.map +1 -1
- package/dist/{index-CRuq6HVi.js → index-B9i_mXXp.js} +4 -4
- package/dist/index-B9i_mXXp.js.map +1 -0
- package/dist/{index-r45w9hEq.js → index-D2OGsG4v.js} +2 -2
- package/dist/index-D2OGsG4v.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/interfaces/IItem.d.ts +2 -0
- package/dist/interfaces/IItem.d.ts.map +1 -1
- package/dist/interfaces/IItemProperty.d.ts +1 -0
- package/dist/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/main.cjs +2 -2
- package/dist/main.js +996 -1030
- package/dist/main.js.map +1 -1
- package/dist/node.js +11 -11
- package/dist/node.js.map +1 -1
- package/dist/{property-Dy09KTxg.js → property-fK7tSUDX.js} +7 -5
- package/dist/property-fK7tSUDX.js.map +1 -0
- package/dist/{queries-LZYSuhtz.js → queries-DGOk16cd.js} +2 -2
- package/dist/{queries-LZYSuhtz.js.map → queries-DGOk16cd.js.map} +1 -1
- package/dist/services/write/actors/validateEntity.d.ts.map +1 -1
- package/dist/services/write/actors/writeToDatabase.d.ts.map +1 -1
- package/dist/services/write/writeProcessMachine.d.ts +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/item.d.ts +12 -0
- package/dist/types/item.d.ts.map +1 -1
- package/dist/types/property.d.ts +6 -0
- package/dist/types/property.d.ts.map +1 -1
- package/dist/types/publish.d.ts +9 -0
- package/dist/types/publish.d.ts.map +1 -0
- package/package.json +7 -3
- package/dist/ModelProperty-Cr3BmgkC.js.map +0 -1
- package/dist/Schema-DeKabJ0T.js.map +0 -1
- package/dist/cjs/ModelProperty-MkN5Rmx7.js.map +0 -1
- package/dist/cjs/Schema-B5cr_JVK.js.map +0 -1
- package/dist/cjs/getPublishPayload-DbOc3WA-.js.map +0 -1
- package/dist/cjs/getPublishUploads-NzioLz-3.js.map +0 -1
- package/dist/cjs/index-BmIVfqGN.js.map +0 -1
- package/dist/cjs/index-C_0angRB.js.map +0 -1
- package/dist/events/item/publish.d.ts +0 -7
- package/dist/events/item/publish.d.ts.map +0 -1
- package/dist/getPublishPayload-NFpqbd_H.js.map +0 -1
- package/dist/getPublishUploads-Cpb9vgwE.js.map +0 -1
- package/dist/index-CRuq6HVi.js.map +0 -1
- package/dist/index-r45w9hEq.js.map +0 -1
- package/dist/json-I3vJhXo8.js.map +0 -1
- package/dist/property-Dy09KTxg.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fromCallback, setup, assign, createActor } from 'xstate';
|
|
2
|
-
import { a as ModelPropertyDataTypes, ad as getLatestSchemaVersion, s as BaseFileManager, p as BaseDb, q as models, ae as
|
|
2
|
+
import { a as ModelPropertyDataTypes, ad as getLatestSchemaVersion, s as BaseFileManager, p as BaseDb, q as models, ae as createModelsFromJson, aa as loadSchemaFromFile, af as writeProcessMachine, r as properties, W as schemas, G as modelSchemas, ag as generateId, ah as waitForEntityIdle, ai as createReactiveProxy, aj as findEntity, ak as forceRemoveFromCaches, al as runDestroyLifecycle } from './ClientManager-DoHUt8tU.js';
|
|
3
3
|
import 'pluralize';
|
|
4
|
-
import { eq } from 'drizzle-orm';
|
|
4
|
+
import { eq, and } from 'drizzle-orm';
|
|
5
5
|
import debug from 'debug';
|
|
6
6
|
|
|
7
7
|
const logger$4 = debug('seedSdk:helpers:updateSchema');
|
|
@@ -50,9 +50,9 @@ const getSchemaFilePath = (name, version, schemaFileId) => {
|
|
|
50
50
|
* @throws Error if schema not found or missing schemaFileId
|
|
51
51
|
*/
|
|
52
52
|
async function getSchemaFileId(schemaName) {
|
|
53
|
-
const { BaseDb } = await import('./
|
|
53
|
+
const { BaseDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aP; });
|
|
54
54
|
const db = BaseDb.getAppDb();
|
|
55
|
-
const { schemas } = await import('./
|
|
55
|
+
const { schemas } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aU; });
|
|
56
56
|
const { eq, desc } = await import('drizzle-orm');
|
|
57
57
|
const dbSchema = await db
|
|
58
58
|
.select()
|
|
@@ -65,6 +65,40 @@ async function getSchemaFileId(schemaName) {
|
|
|
65
65
|
}
|
|
66
66
|
return dbSchema[0].schemaFileId;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Write the full schema to a new version file (e.g. when new models were added).
|
|
70
|
+
* Used when _editedProperties contains 'schema:models' and there are no property-level updates.
|
|
71
|
+
* @param schemaName - Schema name
|
|
72
|
+
* @param schema - Full schema object (e.g. from _buildModelsFromInstances)
|
|
73
|
+
* @returns The file path of the new schema version
|
|
74
|
+
*/
|
|
75
|
+
async function writeFullSchemaNewVersion(schemaName, schema) {
|
|
76
|
+
const latestVersion = await getLatestSchemaVersion(schemaName);
|
|
77
|
+
const newVersion = latestVersion + 1;
|
|
78
|
+
const schemaWithNewVersion = {
|
|
79
|
+
...schema,
|
|
80
|
+
version: newVersion,
|
|
81
|
+
metadata: {
|
|
82
|
+
...schema.metadata,
|
|
83
|
+
updatedAt: new Date().toISOString(),
|
|
84
|
+
},
|
|
85
|
+
migrations: [
|
|
86
|
+
...(schema.migrations || []),
|
|
87
|
+
{
|
|
88
|
+
version: newVersion,
|
|
89
|
+
timestamp: new Date().toISOString(),
|
|
90
|
+
description: 'New schema version (e.g. new models added)',
|
|
91
|
+
changes: [{ type: 'full_schema_write' }],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
const newFilePath = getSchemaFilePath(schemaName, newVersion, schema.id ?? (await getSchemaFileId(schemaName)));
|
|
96
|
+
const newContent = JSON.stringify(schemaWithNewVersion, null, 2);
|
|
97
|
+
await BaseFileManager.saveFile(newFilePath, newContent);
|
|
98
|
+
await BaseFileManager.waitForFileWithContent(newFilePath);
|
|
99
|
+
logger$4(`Created new schema version ${newVersion} for ${schemaName} at ${newFilePath}`);
|
|
100
|
+
return newFilePath;
|
|
101
|
+
}
|
|
68
102
|
/**
|
|
69
103
|
* Get model name from modelId
|
|
70
104
|
* @param modelId - The model ID to look up
|
|
@@ -317,11 +351,9 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
317
351
|
},
|
|
318
352
|
])),
|
|
319
353
|
};
|
|
320
|
-
// Use dynamic import to break circular dependency
|
|
321
|
-
const { createModelsFromJson } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
|
|
322
354
|
// Generate schema ID if missing
|
|
323
355
|
if (!schemaFile.id) {
|
|
324
|
-
const { generateId } = await import('./
|
|
356
|
+
const { generateId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aS; });
|
|
325
357
|
schemaFile.id = generateId();
|
|
326
358
|
logger$4('Generated schema ID for schema:', schemaFile.id);
|
|
327
359
|
}
|
|
@@ -329,7 +361,7 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
329
361
|
// This ensures Model instances are created with correct IDs
|
|
330
362
|
const modelFileIds = new Map();
|
|
331
363
|
const propertyFileIds = new Map();
|
|
332
|
-
const { generateId } = await import('./
|
|
364
|
+
const { generateId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aS; });
|
|
333
365
|
for (const [modelName, model] of Object.entries(schemaFile.models)) {
|
|
334
366
|
// Generate model ID if missing
|
|
335
367
|
if (!model.id) {
|
|
@@ -364,7 +396,7 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
364
396
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
365
397
|
};
|
|
366
398
|
// Use dynamic import to break circular dependency
|
|
367
|
-
const { addSchemaToDb, addModelsToDb } = await import('./
|
|
399
|
+
const { addSchemaToDb, addModelsToDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
368
400
|
// Add schema to database with schemaFileId
|
|
369
401
|
const schemaRecord = await addSchemaToDb(schemaInput, schemaFile.id);
|
|
370
402
|
// Add models to database with model renames handled and schemaFileIds
|
|
@@ -473,8 +505,6 @@ async function renameModelProperty(schemaName, modelName, oldPropertyName, newPr
|
|
|
473
505
|
// Wait for the file to be available with content (important for browser/OPFS where writes may not be immediately readable)
|
|
474
506
|
await BaseFileManager.waitForFileWithContent(newFilePath);
|
|
475
507
|
logger$4(`Renamed property ${oldPropertyName} to ${newPropertyName} in schema ${schemaName} v${newVersion}`);
|
|
476
|
-
// Use dynamic import to break circular dependency
|
|
477
|
-
const { loadSchemaFromFile } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
|
|
478
508
|
// Load the new schema file
|
|
479
509
|
await loadSchemaFromFile(newFilePath);
|
|
480
510
|
return newFilePath;
|
|
@@ -614,8 +644,6 @@ async function deleteModelFromSchema(schemaName, modelName, options = {}) {
|
|
|
614
644
|
// Wait for the file to be available with content (important for browser/OPFS where writes may not be immediately readable)
|
|
615
645
|
await BaseFileManager.waitForFileWithContent(newFilePath);
|
|
616
646
|
logger$4(`Deleted model ${modelName} from schema ${schemaName} v${newVersion}`);
|
|
617
|
-
// Use dynamic import to break circular dependency
|
|
618
|
-
const { loadSchemaFromFile } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
|
|
619
647
|
// Load the new schema file
|
|
620
648
|
await loadSchemaFromFile(newFilePath);
|
|
621
649
|
return newFilePath;
|
|
@@ -702,8 +730,6 @@ async function deletePropertyFromModel(schemaName, modelName, propertyName, opti
|
|
|
702
730
|
// Wait for the file to be available with content (important for browser/OPFS where writes may not be immediately readable)
|
|
703
731
|
await BaseFileManager.waitForFileWithContent(newFilePath);
|
|
704
732
|
logger$4(`Deleted property ${propertyName} from model ${modelName} in schema ${schemaName} v${newVersion}`);
|
|
705
|
-
// Use dynamic import to break circular dependency
|
|
706
|
-
const { loadSchemaFromFile } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aW; });
|
|
707
733
|
// Load the new schema file
|
|
708
734
|
await loadSchemaFromFile(newFilePath);
|
|
709
735
|
return newFilePath;
|
|
@@ -717,11 +743,11 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
|
717
743
|
*/
|
|
718
744
|
async function getSchemaNameFromModel(modelName) {
|
|
719
745
|
// Get the latest schema files and find which one contains this model
|
|
720
|
-
const { listLatestSchemaFiles } = await import('./
|
|
746
|
+
const { listLatestSchemaFiles } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aY; });
|
|
721
747
|
const latestSchemas = await listLatestSchemaFiles();
|
|
722
748
|
for (const schema of latestSchemas) {
|
|
723
749
|
try {
|
|
724
|
-
const { BaseFileManager } = await import('./
|
|
750
|
+
const { BaseFileManager } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aR; });
|
|
725
751
|
const content = await BaseFileManager.readFileAsString(schema.filePath);
|
|
726
752
|
const schemaFile = JSON.parse(content);
|
|
727
753
|
if (schemaFile.models && schemaFile.models[modelName]) {
|
|
@@ -738,7 +764,7 @@ async function getSchemaNameFromModel(modelName) {
|
|
|
738
764
|
const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
739
765
|
const _saveToSchema = async () => {
|
|
740
766
|
// Use dynamic import to break circular dependency
|
|
741
|
-
const { SchemaValidationService } = await import('./SchemaValidationService-
|
|
767
|
+
const { SchemaValidationService } = await import('./SchemaValidationService-BfoEiHNr.js');
|
|
742
768
|
const validationService = new SchemaValidationService();
|
|
743
769
|
// Validate property structure before saving
|
|
744
770
|
const validationResult = validationService.validatePropertyStructure(context);
|
|
@@ -766,8 +792,8 @@ const saveToSchema = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
766
792
|
await updateModelProperties(schemaName, [propertyUpdate]);
|
|
767
793
|
// Clear isEdited flag in database after saving to schema file
|
|
768
794
|
try {
|
|
769
|
-
const { BaseDb } = await import('./
|
|
770
|
-
const { properties: propertiesTable, models: modelsTable } = await import('./index-
|
|
795
|
+
const { BaseDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aP; });
|
|
796
|
+
const { properties: propertiesTable, models: modelsTable } = await import('./index-D2OGsG4v.js').then(function (n) { return n.s; });
|
|
771
797
|
const { eq, and } = await import('drizzle-orm');
|
|
772
798
|
const db = BaseDb.getAppDb();
|
|
773
799
|
if (db && context.modelName && context.name) {
|
|
@@ -820,45 +846,86 @@ var saveToSchema$1 = /*#__PURE__*/Object.freeze({
|
|
|
820
846
|
const logger$2 = debug('seedSdk:modelProperty:actors:compareAndMarkDraft');
|
|
821
847
|
const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
822
848
|
const _compareAndMarkDraft = async () => {
|
|
849
|
+
// Fill modelName/dataType from _originalValues when missing, then from DB by schemaFileId
|
|
850
|
+
let fullContext = {
|
|
851
|
+
...context,
|
|
852
|
+
modelName: context.modelName ?? context._originalValues?.modelName,
|
|
853
|
+
dataType: context.dataType ?? context._originalValues?.dataType,
|
|
854
|
+
};
|
|
855
|
+
const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
856
|
+
if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
857
|
+
try {
|
|
858
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
859
|
+
let fromDb;
|
|
860
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
861
|
+
fromDb = await getPropertyModelNameAndDataType(schemaFileIdForResolve);
|
|
862
|
+
if (fromDb)
|
|
863
|
+
break;
|
|
864
|
+
if (attempt < 5)
|
|
865
|
+
await new Promise((r) => setTimeout(r, 40));
|
|
866
|
+
}
|
|
867
|
+
if (fromDb) {
|
|
868
|
+
fullContext = {
|
|
869
|
+
...fullContext,
|
|
870
|
+
modelName: fullContext.modelName ?? fromDb.modelName,
|
|
871
|
+
dataType: fullContext.dataType ?? fromDb.dataType,
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
if (fullContext.modelName === undefined && schemaFileIdForResolve) {
|
|
875
|
+
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
876
|
+
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
877
|
+
const pendingModelId = ModelProperty?.getPendingModelId?.(schemaFileIdForResolve);
|
|
878
|
+
if (pendingModelId != null) {
|
|
879
|
+
const modelName = await getModelNameByModelId(pendingModelId);
|
|
880
|
+
if (modelName) {
|
|
881
|
+
fullContext = { ...fullContext, modelName };
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
// ignore
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const schemaFileId = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
823
891
|
// If _originalValues is not set, we still need to save to database if the property exists
|
|
824
892
|
// This handles the case where the name is changed before _originalValues is initialized
|
|
825
|
-
if (!
|
|
893
|
+
if (!fullContext._originalValues) {
|
|
826
894
|
logger$2('No original values to compare against');
|
|
827
|
-
logger$2(`[compareAndMarkDraft] Context: modelName=${
|
|
895
|
+
logger$2(`[compareAndMarkDraft] Context: modelName=${fullContext.modelName}, name=${fullContext.name}, id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}`);
|
|
828
896
|
// If we have a name and modelName, try to save to database anyway
|
|
829
897
|
// This ensures name changes are persisted even if _originalValues isn't initialized yet
|
|
830
898
|
// We need either schemaFileId (id or _propertyFileId) to find the property in the database
|
|
831
|
-
|
|
832
|
-
if (context.modelName && context.name && schemaFileId) {
|
|
899
|
+
if (fullContext.modelName && fullContext.name && schemaFileId) {
|
|
833
900
|
logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
|
|
834
901
|
try {
|
|
835
|
-
const { savePropertyToDb } = await import('./
|
|
902
|
+
const { savePropertyToDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
836
903
|
// Ensure _propertyFileId is set for savePropertyToDb to find the property
|
|
837
904
|
const contextWithFileId = {
|
|
838
|
-
...
|
|
905
|
+
...fullContext,
|
|
839
906
|
_propertyFileId: schemaFileId,
|
|
840
907
|
};
|
|
841
908
|
await savePropertyToDb(contextWithFileId);
|
|
842
|
-
logger$2(`[compareAndMarkDraft] Successfully saved property ${
|
|
909
|
+
logger$2(`[compareAndMarkDraft] Successfully saved property ${fullContext.modelName}:${fullContext.name} to database (no _originalValues)`);
|
|
843
910
|
}
|
|
844
911
|
catch (error) {
|
|
845
912
|
logger$2(`[compareAndMarkDraft] Error saving property to database (no _originalValues): ${error}`);
|
|
846
913
|
// Don't throw - this is a best-effort save, but log the error for debugging
|
|
847
|
-
console.error(`[compareAndMarkDraft] Failed to save property ${
|
|
914
|
+
console.error(`[compareAndMarkDraft] Failed to save property ${fullContext.modelName}:${fullContext.name}:`, error);
|
|
848
915
|
}
|
|
849
916
|
}
|
|
850
917
|
else {
|
|
851
|
-
logger$2(`[compareAndMarkDraft] Cannot save property ${
|
|
918
|
+
logger$2(`[compareAndMarkDraft] Cannot save property ${fullContext.modelName}:${fullContext.name} - missing required fields (schemaFileId: ${schemaFileId})`);
|
|
852
919
|
}
|
|
853
920
|
return;
|
|
854
921
|
}
|
|
855
|
-
logger$2(`[compareAndMarkDraft] Comparing: context.name=${
|
|
922
|
+
logger$2(`[compareAndMarkDraft] Comparing: context.name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
856
923
|
// Compare current values with original
|
|
857
924
|
// Only compare property fields, not internal fields
|
|
858
925
|
const propertyFields = ['name', 'dataType', 'ref', 'refModelName', 'refModelId', 'refValueType', 'storageType', 'localStorageDir', 'filenameSuffix', 'modelName', 'modelId'];
|
|
859
926
|
const hasChanges = propertyFields.some(key => {
|
|
860
|
-
const currentValue =
|
|
861
|
-
const originalValue =
|
|
927
|
+
const currentValue = fullContext[key];
|
|
928
|
+
const originalValue = fullContext._originalValues?.[key];
|
|
862
929
|
// Handle name changes specifically
|
|
863
930
|
if (key === 'name') {
|
|
864
931
|
const nameChanged = currentValue !== originalValue;
|
|
@@ -869,8 +936,8 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
869
936
|
}
|
|
870
937
|
// Handle ref fields - compare by name
|
|
871
938
|
if (key === 'ref' || key === 'refModelName') {
|
|
872
|
-
const currentRef =
|
|
873
|
-
const originalRef =
|
|
939
|
+
const currentRef = fullContext.refModelName || fullContext.ref;
|
|
940
|
+
const originalRef = fullContext._originalValues?.refModelName || fullContext._originalValues?.ref;
|
|
874
941
|
// Both undefined/null means no ref, so they're the same
|
|
875
942
|
if (!currentRef && !originalRef)
|
|
876
943
|
return false;
|
|
@@ -888,53 +955,55 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
888
955
|
return currentValue !== originalValue;
|
|
889
956
|
});
|
|
890
957
|
if (hasChanges) {
|
|
891
|
-
logger$2(`Property ${
|
|
892
|
-
logger$2(`[compareAndMarkDraft] Context when saving: id=${
|
|
958
|
+
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
|
|
959
|
+
logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
893
960
|
// Use dynamic import to break circular dependency
|
|
894
|
-
const { savePropertyToDb } = await import('./
|
|
961
|
+
const { savePropertyToDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
895
962
|
// Save to database (but not JSON file) - always save to DB when there are changes
|
|
896
963
|
try {
|
|
897
|
-
await savePropertyToDb(
|
|
898
|
-
logger$2(`[compareAndMarkDraft] Successfully saved property ${
|
|
964
|
+
await savePropertyToDb(fullContext);
|
|
965
|
+
logger$2(`[compareAndMarkDraft] Successfully saved property ${fullContext.modelName}:${fullContext.name} to database`);
|
|
899
966
|
}
|
|
900
967
|
catch (error) {
|
|
901
968
|
logger$2(`[compareAndMarkDraft] Error saving property to database: ${error}`);
|
|
902
969
|
throw error;
|
|
903
970
|
}
|
|
904
971
|
// Mark schema as draft if schema name is available
|
|
905
|
-
if (
|
|
972
|
+
if (fullContext._schemaName) {
|
|
906
973
|
// Get the Schema instance and mark it as draft
|
|
907
|
-
const { Schema } = await import('./Schema-
|
|
908
|
-
const schema = Schema.create(
|
|
974
|
+
const { Schema } = await import('./Schema-ClTcpgbt.js');
|
|
975
|
+
const schema = Schema.create(fullContext._schemaName, {
|
|
976
|
+
waitForReady: false,
|
|
977
|
+
});
|
|
909
978
|
// Send event to Schema machine to mark as draft
|
|
910
979
|
schema.getService().send({
|
|
911
980
|
type: 'markAsDraft',
|
|
912
|
-
propertyKey: `${
|
|
981
|
+
propertyKey: `${fullContext.modelName}:${fullContext.name}`,
|
|
913
982
|
});
|
|
914
983
|
}
|
|
915
984
|
}
|
|
916
985
|
else {
|
|
917
986
|
// No changes - clear edited flag in database and context
|
|
918
|
-
logger$2(`Property ${
|
|
987
|
+
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
|
|
919
988
|
// Clear isEdited flag in database
|
|
920
989
|
try {
|
|
921
|
-
const { BaseDb } = await import('./
|
|
922
|
-
const { properties: propertiesTable, models: modelsTable } = await import('./index-
|
|
990
|
+
const { BaseDb } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aP; });
|
|
991
|
+
const { properties: propertiesTable, models: modelsTable } = await import('./index-D2OGsG4v.js').then(function (n) { return n.s; });
|
|
923
992
|
const { eq, and } = await import('drizzle-orm');
|
|
924
993
|
const db = BaseDb.getAppDb();
|
|
925
|
-
if (db &&
|
|
994
|
+
if (db && fullContext.modelName && fullContext.name) {
|
|
926
995
|
// Find model by name
|
|
927
996
|
const modelRecords = await db
|
|
928
997
|
.select({ id: modelsTable.id })
|
|
929
998
|
.from(modelsTable)
|
|
930
|
-
.where(eq(modelsTable.name,
|
|
999
|
+
.where(eq(modelsTable.name, fullContext.modelName))
|
|
931
1000
|
.limit(1);
|
|
932
1001
|
if (modelRecords.length > 0) {
|
|
933
1002
|
// Find property by name and modelId
|
|
934
1003
|
const propertyRecords = await db
|
|
935
1004
|
.select({ id: propertiesTable.id })
|
|
936
1005
|
.from(propertiesTable)
|
|
937
|
-
.where(and(eq(propertiesTable.name,
|
|
1006
|
+
.where(and(eq(propertiesTable.name, fullContext.name), eq(propertiesTable.modelId, modelRecords[0].id)))
|
|
938
1007
|
.limit(1);
|
|
939
1008
|
if (propertyRecords.length > 0) {
|
|
940
1009
|
// Clear isEdited flag in database
|
|
@@ -942,7 +1011,7 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
942
1011
|
.update(propertiesTable)
|
|
943
1012
|
.set({ isEdited: false })
|
|
944
1013
|
.where(eq(propertiesTable.id, propertyRecords[0].id));
|
|
945
|
-
logger$2(`Cleared isEdited flag in database for property ${
|
|
1014
|
+
logger$2(`Cleared isEdited flag in database for property ${fullContext.modelName}:${fullContext.name}`);
|
|
946
1015
|
}
|
|
947
1016
|
}
|
|
948
1017
|
}
|
|
@@ -969,20 +1038,82 @@ const compareAndMarkDraft = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
969
1038
|
const logger$1 = debug('seedSdk:modelProperty:actors:validateProperty');
|
|
970
1039
|
const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
971
1040
|
const _validateProperty = async () => {
|
|
972
|
-
|
|
1041
|
+
// Use full context for validation: fill modelName/dataType from _originalValues when missing, then
|
|
1042
|
+
// from DB by schemaFileId (context.id) so just-created renames don't fail structure validation.
|
|
1043
|
+
let fullContext = {
|
|
1044
|
+
...context,
|
|
1045
|
+
modelName: context.modelName ?? context._originalValues?.modelName,
|
|
1046
|
+
dataType: context.dataType ?? context._originalValues?.dataType,
|
|
1047
|
+
};
|
|
1048
|
+
const schemaFileId = typeof context.id === 'string' ? context.id : undefined;
|
|
1049
|
+
if (schemaFileId && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
1050
|
+
// Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
|
|
1051
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
1052
|
+
try {
|
|
1053
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
1054
|
+
// Try pending write first (property row may not exist yet)
|
|
1055
|
+
if (fullContext.modelName === undefined && schemaFileId) {
|
|
1056
|
+
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
1057
|
+
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1058
|
+
const pendingModelId = ModelProperty?.getPendingModelId?.(schemaFileId);
|
|
1059
|
+
if (pendingModelId != null) {
|
|
1060
|
+
const modelName = await getModelNameByModelId(pendingModelId);
|
|
1061
|
+
if (modelName) {
|
|
1062
|
+
fullContext = { ...fullContext, modelName };
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
// Then DB property lookup with retry (catches row after initial write)
|
|
1067
|
+
let fromDb;
|
|
1068
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
1069
|
+
fromDb = await getPropertyModelNameAndDataType(schemaFileId);
|
|
1070
|
+
if (fromDb)
|
|
1071
|
+
break;
|
|
1072
|
+
if (attempt < 5)
|
|
1073
|
+
await new Promise((r) => setTimeout(r, 40));
|
|
1074
|
+
}
|
|
1075
|
+
if (fromDb) {
|
|
1076
|
+
fullContext = {
|
|
1077
|
+
...fullContext,
|
|
1078
|
+
modelName: fullContext.modelName ?? fromDb.modelName,
|
|
1079
|
+
dataType: fullContext.dataType ?? fromDb.dataType,
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
// If still no modelName, try pending write again (may have been set during retries)
|
|
1083
|
+
if (fullContext.modelName === undefined && schemaFileId) {
|
|
1084
|
+
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
1085
|
+
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
1086
|
+
const pendingModelId = ModelProperty?.getPendingModelId?.(schemaFileId);
|
|
1087
|
+
if (pendingModelId != null) {
|
|
1088
|
+
const modelName = await getModelNameByModelId(pendingModelId);
|
|
1089
|
+
if (modelName) {
|
|
1090
|
+
fullContext = { ...fullContext, modelName };
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
catch {
|
|
1096
|
+
// ignore
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
// Last resort for structure validation: TProperty requires dataType; allow name+id to pass if we have schemaFileId
|
|
1100
|
+
if (fullContext.dataType === undefined && (fullContext.modelName !== undefined || schemaFileId)) {
|
|
1101
|
+
fullContext = { ...fullContext, dataType: (fullContext.dataType ?? context._originalValues?.dataType) || 'Text' };
|
|
1102
|
+
}
|
|
1103
|
+
console.log('[validateProperty] Starting validation for property:', fullContext.name);
|
|
973
1104
|
console.log('[validateProperty] Context:', {
|
|
974
|
-
name:
|
|
975
|
-
modelName:
|
|
976
|
-
_schemaName:
|
|
977
|
-
_originalValues:
|
|
1105
|
+
name: fullContext.name,
|
|
1106
|
+
modelName: fullContext.modelName,
|
|
1107
|
+
_schemaName: fullContext._schemaName,
|
|
1108
|
+
_originalValues: fullContext._originalValues
|
|
978
1109
|
});
|
|
979
1110
|
// Use dynamic imports to break circular dependencies
|
|
980
|
-
const { SchemaValidationService } = await import('./SchemaValidationService-
|
|
1111
|
+
const { SchemaValidationService } = await import('./SchemaValidationService-BfoEiHNr.js');
|
|
981
1112
|
const validationService = new SchemaValidationService();
|
|
982
|
-
const { Schema } = await import('./Schema-
|
|
1113
|
+
const { Schema } = await import('./Schema-ClTcpgbt.js');
|
|
983
1114
|
// Validate property structure
|
|
984
1115
|
console.log('[validateProperty] Validating property structure...');
|
|
985
|
-
const structureResult = validationService.validatePropertyStructure(
|
|
1116
|
+
const structureResult = validationService.validatePropertyStructure(fullContext);
|
|
986
1117
|
console.log('[validateProperty] Structure validation result:', structureResult.isValid);
|
|
987
1118
|
if (!structureResult.isValid) {
|
|
988
1119
|
console.log('[validateProperty] Structure validation failed:', structureResult.errors);
|
|
@@ -991,11 +1122,13 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
991
1122
|
}
|
|
992
1123
|
console.log('[validateProperty] Structure validation passed');
|
|
993
1124
|
// If we have schema name and model name, validate against schema
|
|
994
|
-
console.log('[validateProperty] Checking schema validation:', { hasSchemaName: !!
|
|
995
|
-
if (
|
|
1125
|
+
console.log('[validateProperty] Checking schema validation:', { hasSchemaName: !!fullContext._schemaName, hasModelName: !!fullContext.modelName });
|
|
1126
|
+
if (fullContext._schemaName && fullContext.modelName) {
|
|
996
1127
|
try {
|
|
997
|
-
console.log('[validateProperty] Creating schema instance:',
|
|
998
|
-
const schema = Schema.create(
|
|
1128
|
+
console.log('[validateProperty] Creating schema instance:', fullContext._schemaName);
|
|
1129
|
+
const schema = Schema.create(fullContext._schemaName, {
|
|
1130
|
+
waitForReady: false,
|
|
1131
|
+
});
|
|
999
1132
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
1000
1133
|
const schemaStatus = schemaSnapshot.value;
|
|
1001
1134
|
console.log('[validateProperty] Schema status:', schemaStatus);
|
|
@@ -1008,28 +1141,28 @@ const validateProperty = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1008
1141
|
if (schemaContext.models && Object.keys(schemaContext.models).length > 0) {
|
|
1009
1142
|
// If property name has changed, validate against the original name (from schema file)
|
|
1010
1143
|
// This handles the case where a property is renamed - the schema file still has the old name
|
|
1011
|
-
const propertyNameToValidate =
|
|
1012
|
-
?
|
|
1013
|
-
:
|
|
1144
|
+
const propertyNameToValidate = fullContext._originalValues?.name && fullContext._originalValues.name !== fullContext.name
|
|
1145
|
+
? fullContext._originalValues.name
|
|
1146
|
+
: fullContext.name || '';
|
|
1014
1147
|
console.log('[validateProperty] Validating against schema:', {
|
|
1015
|
-
modelName:
|
|
1148
|
+
modelName: fullContext.modelName,
|
|
1016
1149
|
propertyNameToValidate,
|
|
1017
|
-
originalName:
|
|
1018
|
-
currentName:
|
|
1150
|
+
originalName: fullContext._originalValues?.name,
|
|
1151
|
+
currentName: fullContext.name
|
|
1019
1152
|
});
|
|
1020
|
-
const schemaResult = validationService.validateProperty(schemaContext,
|
|
1153
|
+
const schemaResult = validationService.validateProperty(schemaContext, fullContext.modelName, propertyNameToValidate, fullContext);
|
|
1021
1154
|
console.log('[validateProperty] Schema validation result:', { isValid: schemaResult.isValid, errors: schemaResult.errors.length, errorCodes: schemaResult.errors.map(e => e.code) });
|
|
1022
1155
|
if (!schemaResult.isValid) {
|
|
1023
1156
|
// If property was renamed, some validation errors are expected (like property_not_found, missing_type)
|
|
1024
1157
|
// Only fail if it's a critical error that's not related to the rename
|
|
1025
|
-
const isRenamed =
|
|
1158
|
+
const isRenamed = fullContext._originalValues?.name && fullContext._originalValues.name !== fullContext.name;
|
|
1026
1159
|
const criticalErrors = schemaResult.errors.filter(err => {
|
|
1027
1160
|
// Allow property_not_found and missing_type errors when property is renamed
|
|
1028
1161
|
if (isRenamed && (err.code === 'property_not_found' || err.code === 'missing_type')) {
|
|
1029
1162
|
return false; // Not critical
|
|
1030
1163
|
}
|
|
1031
1164
|
// For non-renamed properties, only allow property_not_found if we're validating with the same name
|
|
1032
|
-
if (err.code === 'property_not_found' && propertyNameToValidate ===
|
|
1165
|
+
if (err.code === 'property_not_found' && propertyNameToValidate === fullContext.name) {
|
|
1033
1166
|
return false; // Not critical
|
|
1034
1167
|
}
|
|
1035
1168
|
return true; // Critical error
|
|
@@ -1163,6 +1296,15 @@ const modelPropertyMachine = setup({
|
|
|
1163
1296
|
}
|
|
1164
1297
|
newContext[key] = value;
|
|
1165
1298
|
}
|
|
1299
|
+
// Preserve modelName and dataType from context or _originalValues so validation and savePropertyToDb
|
|
1300
|
+
// never run with missing required/needed fields (e.g. when a just-created property is renamed before
|
|
1301
|
+
// the full context is available from the creator).
|
|
1302
|
+
if (newContext.modelName === undefined && context._originalValues?.modelName !== undefined) {
|
|
1303
|
+
newContext.modelName = context._originalValues.modelName;
|
|
1304
|
+
}
|
|
1305
|
+
if (newContext.dataType === undefined && context._originalValues?.dataType !== undefined) {
|
|
1306
|
+
newContext.dataType = context._originalValues.dataType;
|
|
1307
|
+
}
|
|
1166
1308
|
// Compare with original values and set _isEdited flag (only for non-internal updates)
|
|
1167
1309
|
if (!onlyInternalFields && context._originalValues) {
|
|
1168
1310
|
const hasChanges = Object.keys(event).some((key) => {
|
|
@@ -1232,6 +1374,23 @@ const modelPropertyMachine = setup({
|
|
|
1232
1374
|
_schemaName: event.schemaName,
|
|
1233
1375
|
})),
|
|
1234
1376
|
},
|
|
1377
|
+
destroyStarted: {
|
|
1378
|
+
actions: assign({ _destroyInProgress: true, _destroyError: null }),
|
|
1379
|
+
},
|
|
1380
|
+
destroyDone: {
|
|
1381
|
+
actions: assign({ _destroyInProgress: false }),
|
|
1382
|
+
},
|
|
1383
|
+
destroyError: {
|
|
1384
|
+
actions: assign(({ event }) => ({
|
|
1385
|
+
_destroyInProgress: false,
|
|
1386
|
+
_destroyError: event.error instanceof Error
|
|
1387
|
+
? { message: event.error.message, name: event.error.name }
|
|
1388
|
+
: { message: String(event.error) },
|
|
1389
|
+
})),
|
|
1390
|
+
},
|
|
1391
|
+
clearDestroyError: {
|
|
1392
|
+
actions: assign({ _destroyError: null }),
|
|
1393
|
+
},
|
|
1235
1394
|
},
|
|
1236
1395
|
states: {
|
|
1237
1396
|
idle: {
|
|
@@ -1357,6 +1516,32 @@ const modelPropertyMachine = setup({
|
|
|
1357
1516
|
},
|
|
1358
1517
|
});
|
|
1359
1518
|
|
|
1519
|
+
/**
|
|
1520
|
+
* Returns property rows for a model identified by modelFileId (model's schemaFileId).
|
|
1521
|
+
* Resolves modelFileId -> modelId via models table, then selects all properties where modelId = ?.
|
|
1522
|
+
* Each row includes schemaFileId for use with ModelProperty.createById(schemaFileId).
|
|
1523
|
+
*/
|
|
1524
|
+
const getModelPropertiesData = async (modelFileId) => {
|
|
1525
|
+
const appDb = BaseDb.getAppDb();
|
|
1526
|
+
if (!appDb || !modelFileId) {
|
|
1527
|
+
return [];
|
|
1528
|
+
}
|
|
1529
|
+
const modelRows = await appDb
|
|
1530
|
+
.select({ id: models.id })
|
|
1531
|
+
.from(models)
|
|
1532
|
+
.where(eq(models.schemaFileId, modelFileId))
|
|
1533
|
+
.limit(1);
|
|
1534
|
+
if (modelRows.length === 0) {
|
|
1535
|
+
return [];
|
|
1536
|
+
}
|
|
1537
|
+
const modelId = modelRows[0].id;
|
|
1538
|
+
const rows = await appDb
|
|
1539
|
+
.select()
|
|
1540
|
+
.from(properties)
|
|
1541
|
+
.where(eq(properties.modelId, modelId));
|
|
1542
|
+
return rows;
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1360
1545
|
const logger = debug('seedSdk:modelProperty:ModelProperty');
|
|
1361
1546
|
// Define the property keys from TProperty
|
|
1362
1547
|
const TPropertyKeys = [
|
|
@@ -1523,8 +1708,6 @@ class ModelProperty {
|
|
|
1523
1708
|
return fallbackIsEdited;
|
|
1524
1709
|
}
|
|
1525
1710
|
try {
|
|
1526
|
-
const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
|
|
1527
|
-
const { properties: propertiesTable, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
|
|
1528
1711
|
const { eq, and } = await import('drizzle-orm');
|
|
1529
1712
|
const db = BaseDb.getAppDb();
|
|
1530
1713
|
if (!db) {
|
|
@@ -1532,18 +1715,18 @@ class ModelProperty {
|
|
|
1532
1715
|
}
|
|
1533
1716
|
// Find model by name
|
|
1534
1717
|
const modelRecords = await db
|
|
1535
|
-
.select({ id:
|
|
1536
|
-
.from(
|
|
1537
|
-
.where(eq(
|
|
1718
|
+
.select({ id: models.id })
|
|
1719
|
+
.from(models)
|
|
1720
|
+
.where(eq(models.name, property.modelName))
|
|
1538
1721
|
.limit(1);
|
|
1539
1722
|
if (modelRecords.length === 0) {
|
|
1540
1723
|
return fallbackIsEdited;
|
|
1541
1724
|
}
|
|
1542
1725
|
// Find property by name and modelId
|
|
1543
1726
|
const propertyRecords = await db
|
|
1544
|
-
.select({ isEdited:
|
|
1545
|
-
.from(
|
|
1546
|
-
.where(and(eq(
|
|
1727
|
+
.select({ isEdited: properties.isEdited })
|
|
1728
|
+
.from(properties)
|
|
1729
|
+
.where(and(eq(properties.name, property.name), eq(properties.modelId, modelRecords[0].id)))
|
|
1547
1730
|
.limit(1);
|
|
1548
1731
|
if (propertyRecords.length > 0) {
|
|
1549
1732
|
return propertyRecords[0].isEdited ?? false;
|
|
@@ -1564,9 +1747,6 @@ class ModelProperty {
|
|
|
1564
1747
|
return undefined;
|
|
1565
1748
|
}
|
|
1566
1749
|
try {
|
|
1567
|
-
const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
|
|
1568
|
-
const seedSchema = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
|
|
1569
|
-
const modelsTable = seedSchema.models;
|
|
1570
1750
|
const { eq } = await import('drizzle-orm');
|
|
1571
1751
|
const db = BaseDb.getAppDb();
|
|
1572
1752
|
if (!db) {
|
|
@@ -1574,8 +1754,8 @@ class ModelProperty {
|
|
|
1574
1754
|
}
|
|
1575
1755
|
const refModelRecords = await db
|
|
1576
1756
|
.select()
|
|
1577
|
-
.from(
|
|
1578
|
-
.where(eq(
|
|
1757
|
+
.from(models)
|
|
1758
|
+
.where(eq(models.name, refModelName))
|
|
1579
1759
|
.limit(1);
|
|
1580
1760
|
if (refModelRecords.length > 0 && refModelRecords[0].id) {
|
|
1581
1761
|
return refModelRecords[0].id;
|
|
@@ -1596,8 +1776,8 @@ class ModelProperty {
|
|
|
1596
1776
|
return undefined;
|
|
1597
1777
|
}
|
|
1598
1778
|
try {
|
|
1599
|
-
const { Model } = await import('./
|
|
1600
|
-
const { modelPropertiesToObject } = await import('./
|
|
1779
|
+
const { Model } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aX; });
|
|
1780
|
+
const { modelPropertiesToObject } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aV; });
|
|
1601
1781
|
const model = await Model.getByNameAsync(property.modelName);
|
|
1602
1782
|
if (!model || !model.properties || model.properties.length === 0) {
|
|
1603
1783
|
return undefined;
|
|
@@ -1646,11 +1826,6 @@ class ModelProperty {
|
|
|
1646
1826
|
// Try to get schema name from database first (more reliable)
|
|
1647
1827
|
if (this.modelId) {
|
|
1648
1828
|
try {
|
|
1649
|
-
const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
|
|
1650
|
-
const seedSchema = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
|
|
1651
|
-
const modelsTable = seedSchema.models;
|
|
1652
|
-
const modelSchemas = seedSchema.modelSchemas;
|
|
1653
|
-
const schemas = seedSchema.schemas;
|
|
1654
1829
|
const { eq } = await import('drizzle-orm');
|
|
1655
1830
|
const db = BaseDb.getAppDb();
|
|
1656
1831
|
if (db) {
|
|
@@ -1660,8 +1835,8 @@ class ModelProperty {
|
|
|
1660
1835
|
})
|
|
1661
1836
|
.from(modelSchemas)
|
|
1662
1837
|
.innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))
|
|
1663
|
-
.innerJoin(
|
|
1664
|
-
.where(eq(
|
|
1838
|
+
.innerJoin(models, eq(modelSchemas.modelId, models.id))
|
|
1839
|
+
.where(eq(models.id, this.modelId))
|
|
1665
1840
|
.limit(1);
|
|
1666
1841
|
if (modelSchemaRecords.length > 0) {
|
|
1667
1842
|
schemaName = modelSchemaRecords[0].schemaName;
|
|
@@ -1699,10 +1874,12 @@ class ModelProperty {
|
|
|
1699
1874
|
schemaName,
|
|
1700
1875
|
});
|
|
1701
1876
|
}
|
|
1702
|
-
static create(property) {
|
|
1877
|
+
static create(property, options) {
|
|
1703
1878
|
if (!property) {
|
|
1704
1879
|
throw new Error('Property is required');
|
|
1705
1880
|
}
|
|
1881
|
+
const waitForReady = options?.waitForReady !== false;
|
|
1882
|
+
const readyTimeout = options?.readyTimeout ?? 5000;
|
|
1706
1883
|
// Debug: Log what's being passed to create()
|
|
1707
1884
|
console.log(`[ModelProperty.create] Input property data:`, JSON.stringify({
|
|
1708
1885
|
name: property.name,
|
|
@@ -1776,7 +1953,9 @@ class ModelProperty {
|
|
|
1776
1953
|
instance,
|
|
1777
1954
|
refCount: refCount + 1,
|
|
1778
1955
|
});
|
|
1779
|
-
|
|
1956
|
+
if (!waitForReady)
|
|
1957
|
+
return instance;
|
|
1958
|
+
return waitForEntityIdle(instance, { timeout: readyTimeout }).then(() => instance);
|
|
1780
1959
|
}
|
|
1781
1960
|
// Debug: Log what's being passed to the constructor
|
|
1782
1961
|
console.log(`[ModelProperty.create] propertyWithId before constructor:`, JSON.stringify({
|
|
@@ -1851,7 +2030,7 @@ class ModelProperty {
|
|
|
1851
2030
|
else if (typeof propertyWithId.modelId === 'string') {
|
|
1852
2031
|
// modelId is a string (modelFileId), need to convert to database ID
|
|
1853
2032
|
try {
|
|
1854
|
-
const { getModelIdByFileId } = await import('./
|
|
2033
|
+
const { getModelIdByFileId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
1855
2034
|
resolvedModelId = await getModelIdByFileId(propertyWithId.modelId);
|
|
1856
2035
|
logger(`Converted modelFileId "${propertyWithId.modelId}" to database modelId: ${resolvedModelId}`);
|
|
1857
2036
|
}
|
|
@@ -1864,7 +2043,7 @@ class ModelProperty {
|
|
|
1864
2043
|
// If we still don't have a modelId, try to resolve it from modelName
|
|
1865
2044
|
if (!resolvedModelId && propertyWithId.modelName) {
|
|
1866
2045
|
try {
|
|
1867
|
-
const { getModelId } = await import('./
|
|
2046
|
+
const { getModelId } = await import('./ClientManager-DoHUt8tU.js').then(function (n) { return n.aW; });
|
|
1868
2047
|
// Get schemaName from context if available
|
|
1869
2048
|
const schemaName = snapshot.context._schemaName;
|
|
1870
2049
|
resolvedModelId = await getModelId(propertyWithId.modelName, schemaName);
|
|
@@ -1938,7 +2117,9 @@ class ModelProperty {
|
|
|
1938
2117
|
// Start checking after a short delay to allow state machine to initialize
|
|
1939
2118
|
setTimeout(checkAndSend, 0);
|
|
1940
2119
|
}
|
|
1941
|
-
|
|
2120
|
+
if (!waitForReady)
|
|
2121
|
+
return proxiedInstance;
|
|
2122
|
+
return waitForEntityIdle(proxiedInstance, { timeout: readyTimeout }).then(() => proxiedInstance);
|
|
1942
2123
|
}
|
|
1943
2124
|
/**
|
|
1944
2125
|
* Get ModelProperty instance by propertyFileId from static cache
|
|
@@ -1971,8 +2152,6 @@ class ModelProperty {
|
|
|
1971
2152
|
return cachedInstance;
|
|
1972
2153
|
}
|
|
1973
2154
|
// Query database to get property data from ID
|
|
1974
|
-
const { BaseDb } = await import('./json-I3vJhXo8.js').then(function (n) { return n.aI; });
|
|
1975
|
-
const { properties: propertiesTable, models: modelsTable } = await import('./index-r45w9hEq.js').then(function (n) { return n.s; });
|
|
1976
2155
|
const { eq } = await import('drizzle-orm');
|
|
1977
2156
|
const db = BaseDb.getAppDb();
|
|
1978
2157
|
console.log('db', !!db);
|
|
@@ -1982,13 +2161,13 @@ class ModelProperty {
|
|
|
1982
2161
|
}
|
|
1983
2162
|
const testRecords = await db
|
|
1984
2163
|
.select()
|
|
1985
|
-
.from(
|
|
2164
|
+
.from(properties)
|
|
1986
2165
|
.limit(100);
|
|
1987
2166
|
console.log('testRecords', testRecords);
|
|
1988
2167
|
const propertyRecords = await db
|
|
1989
2168
|
.select()
|
|
1990
|
-
.from(
|
|
1991
|
-
.where(eq(
|
|
2169
|
+
.from(properties)
|
|
2170
|
+
.where(eq(properties.schemaFileId, propertyFileId))
|
|
1992
2171
|
.limit(1);
|
|
1993
2172
|
console.log('propertyRecords', propertyRecords);
|
|
1994
2173
|
if (propertyRecords.length === 0) {
|
|
@@ -1997,9 +2176,9 @@ class ModelProperty {
|
|
|
1997
2176
|
const propertyRecord = propertyRecords[0];
|
|
1998
2177
|
// Get model name
|
|
1999
2178
|
const modelRecords = await db
|
|
2000
|
-
.select({ name:
|
|
2001
|
-
.from(
|
|
2002
|
-
.where(eq(
|
|
2179
|
+
.select({ name: models.name })
|
|
2180
|
+
.from(models)
|
|
2181
|
+
.where(eq(models.id, propertyRecord.modelId))
|
|
2003
2182
|
.limit(1);
|
|
2004
2183
|
if (modelRecords.length === 0) {
|
|
2005
2184
|
return undefined;
|
|
@@ -2022,17 +2201,17 @@ class ModelProperty {
|
|
|
2022
2201
|
// Get ref model name if applicable
|
|
2023
2202
|
if (propertyRecord.refModelId) {
|
|
2024
2203
|
const refModelRecords = await db
|
|
2025
|
-
.select({ name:
|
|
2026
|
-
.from(
|
|
2027
|
-
.where(eq(
|
|
2204
|
+
.select({ name: models.name })
|
|
2205
|
+
.from(models)
|
|
2206
|
+
.where(eq(models.id, propertyRecord.refModelId))
|
|
2028
2207
|
.limit(1);
|
|
2029
2208
|
if (refModelRecords.length > 0) {
|
|
2030
2209
|
propertyData.refModelName = refModelRecords[0].name;
|
|
2031
2210
|
propertyData.ref = refModelRecords[0].name;
|
|
2032
2211
|
}
|
|
2033
2212
|
}
|
|
2034
|
-
// Create ModelProperty instance
|
|
2035
|
-
const instance = this.create(propertyData);
|
|
2213
|
+
// Create ModelProperty instance (sync for createById so we can send updateContext)
|
|
2214
|
+
const instance = this.create(propertyData, { waitForReady: false });
|
|
2036
2215
|
// Set isEdited from database after creation
|
|
2037
2216
|
if (isEditedFromDb) {
|
|
2038
2217
|
instance._service.send({
|
|
@@ -2060,6 +2239,32 @@ class ModelProperty {
|
|
|
2060
2239
|
readyTimeout,
|
|
2061
2240
|
});
|
|
2062
2241
|
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Get all ModelProperty instances for a model.
|
|
2244
|
+
* Loads property rows from DB for the given modelFileId, creates instances via createById, optionally waits for idle.
|
|
2245
|
+
*/
|
|
2246
|
+
static async all(modelFileId, options) {
|
|
2247
|
+
const { waitForReady = false, readyTimeout = 5000 } = options ?? {};
|
|
2248
|
+
if (!modelFileId) {
|
|
2249
|
+
return [];
|
|
2250
|
+
}
|
|
2251
|
+
const rows = await getModelPropertiesData(modelFileId);
|
|
2252
|
+
const instances = [];
|
|
2253
|
+
for (const row of rows) {
|
|
2254
|
+
if (row.schemaFileId) {
|
|
2255
|
+
const instance = await this.createById(row.schemaFileId);
|
|
2256
|
+
if (instance) {
|
|
2257
|
+
instances.push(instance);
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
if (waitForReady && instances.length > 0) {
|
|
2262
|
+
await Promise.all(instances.map((p) => waitForEntityIdle(p, {
|
|
2263
|
+
timeout: readyTimeout,
|
|
2264
|
+
})));
|
|
2265
|
+
}
|
|
2266
|
+
return instances;
|
|
2267
|
+
}
|
|
2063
2268
|
/**
|
|
2064
2269
|
* Track a pending write for a property
|
|
2065
2270
|
*/
|
|
@@ -2098,6 +2303,13 @@ class ModelProperty {
|
|
|
2098
2303
|
.filter(([_, write]) => write.modelId === modelId && write.status !== 'error')
|
|
2099
2304
|
.map(([propertyFileId]) => propertyFileId);
|
|
2100
2305
|
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Get modelId for a property that has a pending write (row may not be in DB yet).
|
|
2308
|
+
* Used to resolve modelName when validating a just-created property rename.
|
|
2309
|
+
*/
|
|
2310
|
+
static getPendingModelId(propertyFileId) {
|
|
2311
|
+
return this.pendingWrites.get(propertyFileId)?.modelId;
|
|
2312
|
+
}
|
|
2101
2313
|
getService() {
|
|
2102
2314
|
return this._service;
|
|
2103
2315
|
}
|
|
@@ -2204,6 +2416,61 @@ class ModelProperty {
|
|
|
2204
2416
|
// Service might already be stopped
|
|
2205
2417
|
}
|
|
2206
2418
|
}
|
|
2419
|
+
/**
|
|
2420
|
+
* Destroy the model property: remove from caches, delete from database, update Schema context, stop service.
|
|
2421
|
+
*/
|
|
2422
|
+
async destroy() {
|
|
2423
|
+
const context = this._getSnapshotContext();
|
|
2424
|
+
const cacheKey = context.modelName && context.name
|
|
2425
|
+
? `${context.modelName}:${context.name}`
|
|
2426
|
+
: (context.id ?? '');
|
|
2427
|
+
if (!cacheKey)
|
|
2428
|
+
return;
|
|
2429
|
+
forceRemoveFromCaches(this, {
|
|
2430
|
+
getCacheKeys: () => [cacheKey],
|
|
2431
|
+
caches: [ModelProperty.instanceCache],
|
|
2432
|
+
});
|
|
2433
|
+
await runDestroyLifecycle(this, {
|
|
2434
|
+
getService: (instance) => instance._service,
|
|
2435
|
+
doDestroy: async () => {
|
|
2436
|
+
const db = BaseDb.getAppDb();
|
|
2437
|
+
const schemaName = context._schemaName;
|
|
2438
|
+
const modelName = context.modelName;
|
|
2439
|
+
const propertyName = context.name;
|
|
2440
|
+
if (!modelName || !propertyName)
|
|
2441
|
+
return;
|
|
2442
|
+
if (db && schemaName) {
|
|
2443
|
+
const propertyRecords = await db
|
|
2444
|
+
.select({ propertyId: properties.id })
|
|
2445
|
+
.from(properties)
|
|
2446
|
+
.innerJoin(models, eq(properties.modelId, models.id))
|
|
2447
|
+
.innerJoin(modelSchemas, eq(models.id, modelSchemas.modelId))
|
|
2448
|
+
.innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))
|
|
2449
|
+
.where(and(eq(schemas.name, schemaName), eq(models.name, modelName), eq(properties.name, propertyName)))
|
|
2450
|
+
.limit(1);
|
|
2451
|
+
if (propertyRecords.length > 0 && propertyRecords[0].propertyId != null) {
|
|
2452
|
+
await db
|
|
2453
|
+
.delete(properties)
|
|
2454
|
+
.where(eq(properties.id, propertyRecords[0].propertyId));
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
if (schemaName) {
|
|
2458
|
+
const { Schema } = await import('./Schema-ClTcpgbt.js');
|
|
2459
|
+
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
2460
|
+
const snapshot = schema.getService().getSnapshot();
|
|
2461
|
+
const schemaContext = snapshot.context;
|
|
2462
|
+
if (schemaContext.models?.[modelName]?.properties?.[propertyName]) {
|
|
2463
|
+
const updatedModels = { ...schemaContext.models };
|
|
2464
|
+
const updatedProperties = { ...updatedModels[modelName].properties };
|
|
2465
|
+
delete updatedProperties[propertyName];
|
|
2466
|
+
updatedModels[modelName] = { ...updatedModels[modelName], properties: updatedProperties };
|
|
2467
|
+
schema.getService().send({ type: 'updateContext', models: updatedModels });
|
|
2468
|
+
schema.getService().send({ type: 'markAsDraft', propertyKey: `property:${modelName}:${propertyName}` });
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
},
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2207
2474
|
}
|
|
2208
2475
|
ModelProperty.instanceCache = new Map();
|
|
2209
2476
|
// Pending writes tracking
|
|
@@ -2214,5 +2481,5 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
2214
2481
|
ModelProperty: ModelProperty
|
|
2215
2482
|
});
|
|
2216
2483
|
|
|
2217
|
-
export { ModelProperty as M, deleteModelFromSchema as a, ModelProperty$1 as b, convertPropertyToSchemaUpdate as c, deletePropertyFromModel as d, renameModelProperty as r, updateModelProperties as u };
|
|
2218
|
-
//# sourceMappingURL=ModelProperty-
|
|
2484
|
+
export { ModelProperty as M, deleteModelFromSchema as a, ModelProperty$1 as b, convertPropertyToSchemaUpdate as c, deletePropertyFromModel as d, renameModelProperty as r, updateModelProperties as u, writeFullSchemaNewVersion as w };
|
|
2485
|
+
//# sourceMappingURL=ModelProperty-gjcA83Mq.js.map
|