@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
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var xstate = require('xstate');
|
|
4
|
-
var main_cjs = require('./index-
|
|
4
|
+
var main_cjs = require('./index-C3j3m34a.js');
|
|
5
5
|
require('pluralize');
|
|
6
6
|
var drizzleOrm = require('drizzle-orm');
|
|
7
7
|
var debug = require('debug');
|
|
@@ -52,9 +52,9 @@ const getSchemaFilePath = (name, version, schemaFileId) => {
|
|
|
52
52
|
* @throws Error if schema not found or missing schemaFileId
|
|
53
53
|
*/
|
|
54
54
|
async function getSchemaFileId(schemaName) {
|
|
55
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-
|
|
55
|
+
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
56
56
|
const db = BaseDb.getAppDb();
|
|
57
|
-
const { schemas } = await Promise.resolve().then(function () { return require('./index-
|
|
57
|
+
const { schemas } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.SchemaSchema; });
|
|
58
58
|
const { eq, desc } = await import('drizzle-orm');
|
|
59
59
|
const dbSchema = await db
|
|
60
60
|
.select()
|
|
@@ -67,6 +67,40 @@ async function getSchemaFileId(schemaName) {
|
|
|
67
67
|
}
|
|
68
68
|
return dbSchema[0].schemaFileId;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Write the full schema to a new version file (e.g. when new models were added).
|
|
72
|
+
* Used when _editedProperties contains 'schema:models' and there are no property-level updates.
|
|
73
|
+
* @param schemaName - Schema name
|
|
74
|
+
* @param schema - Full schema object (e.g. from _buildModelsFromInstances)
|
|
75
|
+
* @returns The file path of the new schema version
|
|
76
|
+
*/
|
|
77
|
+
async function writeFullSchemaNewVersion(schemaName, schema) {
|
|
78
|
+
const latestVersion = await main_cjs.getLatestSchemaVersion(schemaName);
|
|
79
|
+
const newVersion = latestVersion + 1;
|
|
80
|
+
const schemaWithNewVersion = {
|
|
81
|
+
...schema,
|
|
82
|
+
version: newVersion,
|
|
83
|
+
metadata: {
|
|
84
|
+
...schema.metadata,
|
|
85
|
+
updatedAt: new Date().toISOString(),
|
|
86
|
+
},
|
|
87
|
+
migrations: [
|
|
88
|
+
...(schema.migrations || []),
|
|
89
|
+
{
|
|
90
|
+
version: newVersion,
|
|
91
|
+
timestamp: new Date().toISOString(),
|
|
92
|
+
description: 'New schema version (e.g. new models added)',
|
|
93
|
+
changes: [{ type: 'full_schema_write' }],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
const newFilePath = getSchemaFilePath(schemaName, newVersion, schema.id ?? (await getSchemaFileId(schemaName)));
|
|
98
|
+
const newContent = JSON.stringify(schemaWithNewVersion, null, 2);
|
|
99
|
+
await main_cjs.BaseFileManager.saveFile(newFilePath, newContent);
|
|
100
|
+
await main_cjs.BaseFileManager.waitForFileWithContent(newFilePath);
|
|
101
|
+
logger$4(`Created new schema version ${newVersion} for ${schemaName} at ${newFilePath}`);
|
|
102
|
+
return newFilePath;
|
|
103
|
+
}
|
|
70
104
|
/**
|
|
71
105
|
* Get model name from modelId
|
|
72
106
|
* @param modelId - The model ID to look up
|
|
@@ -290,11 +324,9 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
290
324
|
},
|
|
291
325
|
])),
|
|
292
326
|
};
|
|
293
|
-
// Use dynamic import to break circular dependency
|
|
294
|
-
const { createModelsFromJson } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.json; });
|
|
295
327
|
// Generate schema ID if missing
|
|
296
328
|
if (!schemaFile.id) {
|
|
297
|
-
const { generateId } = await Promise.resolve().then(function () { return require('./index-
|
|
329
|
+
const { generateId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.index; });
|
|
298
330
|
schemaFile.id = generateId();
|
|
299
331
|
logger$4('Generated schema ID for schema:', schemaFile.id);
|
|
300
332
|
}
|
|
@@ -302,7 +334,7 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
302
334
|
// This ensures Model instances are created with correct IDs
|
|
303
335
|
const modelFileIds = new Map();
|
|
304
336
|
const propertyFileIds = new Map();
|
|
305
|
-
const { generateId } = await Promise.resolve().then(function () { return require('./index-
|
|
337
|
+
const { generateId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.index; });
|
|
306
338
|
for (const [modelName, model] of Object.entries(schemaFile.models)) {
|
|
307
339
|
// Generate model ID if missing
|
|
308
340
|
if (!model.id) {
|
|
@@ -324,7 +356,7 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
324
356
|
}
|
|
325
357
|
}
|
|
326
358
|
// Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs
|
|
327
|
-
const modelDefinitions = await createModelsFromJson(importData, modelFileIds, propertyFileIds);
|
|
359
|
+
const modelDefinitions = await main_cjs.createModelsFromJson(importData, modelFileIds, propertyFileIds);
|
|
328
360
|
// Convert schema file metadata to schema input for database
|
|
329
361
|
const schemaInput = {
|
|
330
362
|
name: schemaName,
|
|
@@ -337,7 +369,7 @@ async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
|
337
369
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
338
370
|
};
|
|
339
371
|
// Use dynamic import to break circular dependency
|
|
340
|
-
const { addSchemaToDb, addModelsToDb } = await Promise.resolve().then(function () { return require('./index-
|
|
372
|
+
const { addSchemaToDb, addModelsToDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
341
373
|
// Add schema to database with schemaFileId
|
|
342
374
|
const schemaRecord = await addSchemaToDb(schemaInput, schemaFile.id);
|
|
343
375
|
// Add models to database with model renames handled and schemaFileIds
|
|
@@ -362,11 +394,11 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
|
362
394
|
*/
|
|
363
395
|
async function getSchemaNameFromModel(modelName) {
|
|
364
396
|
// Get the latest schema files and find which one contains this model
|
|
365
|
-
const { listLatestSchemaFiles } = await Promise.resolve().then(function () { return require('./index-
|
|
397
|
+
const { listLatestSchemaFiles } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.schema$1; });
|
|
366
398
|
const latestSchemas = await listLatestSchemaFiles();
|
|
367
399
|
for (const schema of latestSchemas) {
|
|
368
400
|
try {
|
|
369
|
-
const { BaseFileManager } = await Promise.resolve().then(function () { return require('./index-
|
|
401
|
+
const { BaseFileManager } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.BaseFileManager$1; });
|
|
370
402
|
const content = await BaseFileManager.readFileAsString(schema.filePath);
|
|
371
403
|
const schemaFile = JSON.parse(content);
|
|
372
404
|
if (schemaFile.models && schemaFile.models[modelName]) {
|
|
@@ -383,7 +415,7 @@ async function getSchemaNameFromModel(modelName) {
|
|
|
383
415
|
const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
384
416
|
const _saveToSchema = async () => {
|
|
385
417
|
// Use dynamic import to break circular dependency
|
|
386
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
418
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DUtQUerg.js'); });
|
|
387
419
|
const validationService = new SchemaValidationService();
|
|
388
420
|
// Validate property structure before saving
|
|
389
421
|
const validationResult = validationService.validatePropertyStructure(context);
|
|
@@ -411,8 +443,8 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
411
443
|
await updateModelProperties(schemaName, [propertyUpdate]);
|
|
412
444
|
// Clear isEdited flag in database after saving to schema file
|
|
413
445
|
try {
|
|
414
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-
|
|
415
|
-
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-
|
|
446
|
+
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
447
|
+
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.schema; });
|
|
416
448
|
const { eq, and } = await import('drizzle-orm');
|
|
417
449
|
const db = BaseDb.getAppDb();
|
|
418
450
|
if (db && context.modelName && context.name) {
|
|
@@ -465,45 +497,86 @@ var saveToSchema$1 = /*#__PURE__*/Object.freeze({
|
|
|
465
497
|
const logger$2 = debug('seedSdk:modelProperty:actors:compareAndMarkDraft');
|
|
466
498
|
const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
467
499
|
const _compareAndMarkDraft = async () => {
|
|
500
|
+
// Fill modelName/dataType from _originalValues when missing, then from DB by schemaFileId
|
|
501
|
+
let fullContext = {
|
|
502
|
+
...context,
|
|
503
|
+
modelName: context.modelName ?? context._originalValues?.modelName,
|
|
504
|
+
dataType: context.dataType ?? context._originalValues?.dataType,
|
|
505
|
+
};
|
|
506
|
+
const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
507
|
+
if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
508
|
+
try {
|
|
509
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
510
|
+
let fromDb;
|
|
511
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
512
|
+
fromDb = await getPropertyModelNameAndDataType(schemaFileIdForResolve);
|
|
513
|
+
if (fromDb)
|
|
514
|
+
break;
|
|
515
|
+
if (attempt < 5)
|
|
516
|
+
await new Promise((r) => setTimeout(r, 40));
|
|
517
|
+
}
|
|
518
|
+
if (fromDb) {
|
|
519
|
+
fullContext = {
|
|
520
|
+
...fullContext,
|
|
521
|
+
modelName: fullContext.modelName ?? fromDb.modelName,
|
|
522
|
+
dataType: fullContext.dataType ?? fromDb.dataType,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
if (fullContext.modelName === undefined && schemaFileIdForResolve) {
|
|
526
|
+
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
527
|
+
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
528
|
+
const pendingModelId = ModelProperty?.getPendingModelId?.(schemaFileIdForResolve);
|
|
529
|
+
if (pendingModelId != null) {
|
|
530
|
+
const modelName = await getModelNameByModelId(pendingModelId);
|
|
531
|
+
if (modelName) {
|
|
532
|
+
fullContext = { ...fullContext, modelName };
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
// ignore
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const schemaFileId = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
468
542
|
// If _originalValues is not set, we still need to save to database if the property exists
|
|
469
543
|
// This handles the case where the name is changed before _originalValues is initialized
|
|
470
|
-
if (!
|
|
544
|
+
if (!fullContext._originalValues) {
|
|
471
545
|
logger$2('No original values to compare against');
|
|
472
|
-
logger$2(`[compareAndMarkDraft] Context: modelName=${
|
|
546
|
+
logger$2(`[compareAndMarkDraft] Context: modelName=${fullContext.modelName}, name=${fullContext.name}, id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}`);
|
|
473
547
|
// If we have a name and modelName, try to save to database anyway
|
|
474
548
|
// This ensures name changes are persisted even if _originalValues isn't initialized yet
|
|
475
549
|
// We need either schemaFileId (id or _propertyFileId) to find the property in the database
|
|
476
|
-
|
|
477
|
-
if (context.modelName && context.name && schemaFileId) {
|
|
550
|
+
if (fullContext.modelName && fullContext.name && schemaFileId) {
|
|
478
551
|
logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
|
|
479
552
|
try {
|
|
480
|
-
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-
|
|
553
|
+
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
481
554
|
// Ensure _propertyFileId is set for savePropertyToDb to find the property
|
|
482
555
|
const contextWithFileId = {
|
|
483
|
-
...
|
|
556
|
+
...fullContext,
|
|
484
557
|
_propertyFileId: schemaFileId,
|
|
485
558
|
};
|
|
486
559
|
await savePropertyToDb(contextWithFileId);
|
|
487
|
-
logger$2(`[compareAndMarkDraft] Successfully saved property ${
|
|
560
|
+
logger$2(`[compareAndMarkDraft] Successfully saved property ${fullContext.modelName}:${fullContext.name} to database (no _originalValues)`);
|
|
488
561
|
}
|
|
489
562
|
catch (error) {
|
|
490
563
|
logger$2(`[compareAndMarkDraft] Error saving property to database (no _originalValues): ${error}`);
|
|
491
564
|
// Don't throw - this is a best-effort save, but log the error for debugging
|
|
492
|
-
console.error(`[compareAndMarkDraft] Failed to save property ${
|
|
565
|
+
console.error(`[compareAndMarkDraft] Failed to save property ${fullContext.modelName}:${fullContext.name}:`, error);
|
|
493
566
|
}
|
|
494
567
|
}
|
|
495
568
|
else {
|
|
496
|
-
logger$2(`[compareAndMarkDraft] Cannot save property ${
|
|
569
|
+
logger$2(`[compareAndMarkDraft] Cannot save property ${fullContext.modelName}:${fullContext.name} - missing required fields (schemaFileId: ${schemaFileId})`);
|
|
497
570
|
}
|
|
498
571
|
return;
|
|
499
572
|
}
|
|
500
|
-
logger$2(`[compareAndMarkDraft] Comparing: context.name=${
|
|
573
|
+
logger$2(`[compareAndMarkDraft] Comparing: context.name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
501
574
|
// Compare current values with original
|
|
502
575
|
// Only compare property fields, not internal fields
|
|
503
576
|
const propertyFields = ['name', 'dataType', 'ref', 'refModelName', 'refModelId', 'refValueType', 'storageType', 'localStorageDir', 'filenameSuffix', 'modelName', 'modelId'];
|
|
504
577
|
const hasChanges = propertyFields.some(key => {
|
|
505
|
-
const currentValue =
|
|
506
|
-
const originalValue =
|
|
578
|
+
const currentValue = fullContext[key];
|
|
579
|
+
const originalValue = fullContext._originalValues?.[key];
|
|
507
580
|
// Handle name changes specifically
|
|
508
581
|
if (key === 'name') {
|
|
509
582
|
const nameChanged = currentValue !== originalValue;
|
|
@@ -514,8 +587,8 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
514
587
|
}
|
|
515
588
|
// Handle ref fields - compare by name
|
|
516
589
|
if (key === 'ref' || key === 'refModelName') {
|
|
517
|
-
const currentRef =
|
|
518
|
-
const originalRef =
|
|
590
|
+
const currentRef = fullContext.refModelName || fullContext.ref;
|
|
591
|
+
const originalRef = fullContext._originalValues?.refModelName || fullContext._originalValues?.ref;
|
|
519
592
|
// Both undefined/null means no ref, so they're the same
|
|
520
593
|
if (!currentRef && !originalRef)
|
|
521
594
|
return false;
|
|
@@ -533,53 +606,55 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
533
606
|
return currentValue !== originalValue;
|
|
534
607
|
});
|
|
535
608
|
if (hasChanges) {
|
|
536
|
-
logger$2(`Property ${
|
|
537
|
-
logger$2(`[compareAndMarkDraft] Context when saving: id=${
|
|
609
|
+
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
|
|
610
|
+
logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
538
611
|
// Use dynamic import to break circular dependency
|
|
539
|
-
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-
|
|
612
|
+
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
540
613
|
// Save to database (but not JSON file) - always save to DB when there are changes
|
|
541
614
|
try {
|
|
542
|
-
await savePropertyToDb(
|
|
543
|
-
logger$2(`[compareAndMarkDraft] Successfully saved property ${
|
|
615
|
+
await savePropertyToDb(fullContext);
|
|
616
|
+
logger$2(`[compareAndMarkDraft] Successfully saved property ${fullContext.modelName}:${fullContext.name} to database`);
|
|
544
617
|
}
|
|
545
618
|
catch (error) {
|
|
546
619
|
logger$2(`[compareAndMarkDraft] Error saving property to database: ${error}`);
|
|
547
620
|
throw error;
|
|
548
621
|
}
|
|
549
622
|
// Mark schema as draft if schema name is available
|
|
550
|
-
if (
|
|
623
|
+
if (fullContext._schemaName) {
|
|
551
624
|
// Get the Schema instance and mark it as draft
|
|
552
|
-
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-
|
|
553
|
-
const schema = Schema.create(
|
|
625
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-CV9hMg8m.js'); });
|
|
626
|
+
const schema = Schema.create(fullContext._schemaName, {
|
|
627
|
+
waitForReady: false,
|
|
628
|
+
});
|
|
554
629
|
// Send event to Schema machine to mark as draft
|
|
555
630
|
schema.getService().send({
|
|
556
631
|
type: 'markAsDraft',
|
|
557
|
-
propertyKey: `${
|
|
632
|
+
propertyKey: `${fullContext.modelName}:${fullContext.name}`,
|
|
558
633
|
});
|
|
559
634
|
}
|
|
560
635
|
}
|
|
561
636
|
else {
|
|
562
637
|
// No changes - clear edited flag in database and context
|
|
563
|
-
logger$2(`Property ${
|
|
638
|
+
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
|
|
564
639
|
// Clear isEdited flag in database
|
|
565
640
|
try {
|
|
566
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-
|
|
567
|
-
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-
|
|
641
|
+
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
642
|
+
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.schema; });
|
|
568
643
|
const { eq, and } = await import('drizzle-orm');
|
|
569
644
|
const db = BaseDb.getAppDb();
|
|
570
|
-
if (db &&
|
|
645
|
+
if (db && fullContext.modelName && fullContext.name) {
|
|
571
646
|
// Find model by name
|
|
572
647
|
const modelRecords = await db
|
|
573
648
|
.select({ id: modelsTable.id })
|
|
574
649
|
.from(modelsTable)
|
|
575
|
-
.where(eq(modelsTable.name,
|
|
650
|
+
.where(eq(modelsTable.name, fullContext.modelName))
|
|
576
651
|
.limit(1);
|
|
577
652
|
if (modelRecords.length > 0) {
|
|
578
653
|
// Find property by name and modelId
|
|
579
654
|
const propertyRecords = await db
|
|
580
655
|
.select({ id: propertiesTable.id })
|
|
581
656
|
.from(propertiesTable)
|
|
582
|
-
.where(and(eq(propertiesTable.name,
|
|
657
|
+
.where(and(eq(propertiesTable.name, fullContext.name), eq(propertiesTable.modelId, modelRecords[0].id)))
|
|
583
658
|
.limit(1);
|
|
584
659
|
if (propertyRecords.length > 0) {
|
|
585
660
|
// Clear isEdited flag in database
|
|
@@ -587,7 +662,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
587
662
|
.update(propertiesTable)
|
|
588
663
|
.set({ isEdited: false })
|
|
589
664
|
.where(eq(propertiesTable.id, propertyRecords[0].id));
|
|
590
|
-
logger$2(`Cleared isEdited flag in database for property ${
|
|
665
|
+
logger$2(`Cleared isEdited flag in database for property ${fullContext.modelName}:${fullContext.name}`);
|
|
591
666
|
}
|
|
592
667
|
}
|
|
593
668
|
}
|
|
@@ -614,20 +689,82 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
614
689
|
const logger$1 = debug('seedSdk:modelProperty:actors:validateProperty');
|
|
615
690
|
const validateProperty = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
616
691
|
const _validateProperty = async () => {
|
|
617
|
-
|
|
692
|
+
// Use full context for validation: fill modelName/dataType from _originalValues when missing, then
|
|
693
|
+
// from DB by schemaFileId (context.id) so just-created renames don't fail structure validation.
|
|
694
|
+
let fullContext = {
|
|
695
|
+
...context,
|
|
696
|
+
modelName: context.modelName ?? context._originalValues?.modelName,
|
|
697
|
+
dataType: context.dataType ?? context._originalValues?.dataType,
|
|
698
|
+
};
|
|
699
|
+
const schemaFileId = typeof context.id === 'string' ? context.id : undefined;
|
|
700
|
+
if (schemaFileId && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
701
|
+
// Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
|
|
702
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
703
|
+
try {
|
|
704
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
705
|
+
// Try pending write first (property row may not exist yet)
|
|
706
|
+
if (fullContext.modelName === undefined && schemaFileId) {
|
|
707
|
+
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
708
|
+
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
709
|
+
const pendingModelId = ModelProperty?.getPendingModelId?.(schemaFileId);
|
|
710
|
+
if (pendingModelId != null) {
|
|
711
|
+
const modelName = await getModelNameByModelId(pendingModelId);
|
|
712
|
+
if (modelName) {
|
|
713
|
+
fullContext = { ...fullContext, modelName };
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
// Then DB property lookup with retry (catches row after initial write)
|
|
718
|
+
let fromDb;
|
|
719
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
720
|
+
fromDb = await getPropertyModelNameAndDataType(schemaFileId);
|
|
721
|
+
if (fromDb)
|
|
722
|
+
break;
|
|
723
|
+
if (attempt < 5)
|
|
724
|
+
await new Promise((r) => setTimeout(r, 40));
|
|
725
|
+
}
|
|
726
|
+
if (fromDb) {
|
|
727
|
+
fullContext = {
|
|
728
|
+
...fullContext,
|
|
729
|
+
modelName: fullContext.modelName ?? fromDb.modelName,
|
|
730
|
+
dataType: fullContext.dataType ?? fromDb.dataType,
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
// If still no modelName, try pending write again (may have been set during retries)
|
|
734
|
+
if (fullContext.modelName === undefined && schemaFileId) {
|
|
735
|
+
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
736
|
+
const ModelProperty = mod?.ModelProperty ?? mod?.default;
|
|
737
|
+
const pendingModelId = ModelProperty?.getPendingModelId?.(schemaFileId);
|
|
738
|
+
if (pendingModelId != null) {
|
|
739
|
+
const modelName = await getModelNameByModelId(pendingModelId);
|
|
740
|
+
if (modelName) {
|
|
741
|
+
fullContext = { ...fullContext, modelName };
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
catch {
|
|
747
|
+
// ignore
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
// Last resort for structure validation: TProperty requires dataType; allow name+id to pass if we have schemaFileId
|
|
751
|
+
if (fullContext.dataType === undefined && (fullContext.modelName !== undefined || schemaFileId)) {
|
|
752
|
+
fullContext = { ...fullContext, dataType: (fullContext.dataType ?? context._originalValues?.dataType) || 'Text' };
|
|
753
|
+
}
|
|
754
|
+
console.log('[validateProperty] Starting validation for property:', fullContext.name);
|
|
618
755
|
console.log('[validateProperty] Context:', {
|
|
619
|
-
name:
|
|
620
|
-
modelName:
|
|
621
|
-
_schemaName:
|
|
622
|
-
_originalValues:
|
|
756
|
+
name: fullContext.name,
|
|
757
|
+
modelName: fullContext.modelName,
|
|
758
|
+
_schemaName: fullContext._schemaName,
|
|
759
|
+
_originalValues: fullContext._originalValues
|
|
623
760
|
});
|
|
624
761
|
// Use dynamic imports to break circular dependencies
|
|
625
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
762
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-DUtQUerg.js'); });
|
|
626
763
|
const validationService = new SchemaValidationService();
|
|
627
|
-
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-
|
|
764
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-CV9hMg8m.js'); });
|
|
628
765
|
// Validate property structure
|
|
629
766
|
console.log('[validateProperty] Validating property structure...');
|
|
630
|
-
const structureResult = validationService.validatePropertyStructure(
|
|
767
|
+
const structureResult = validationService.validatePropertyStructure(fullContext);
|
|
631
768
|
console.log('[validateProperty] Structure validation result:', structureResult.isValid);
|
|
632
769
|
if (!structureResult.isValid) {
|
|
633
770
|
console.log('[validateProperty] Structure validation failed:', structureResult.errors);
|
|
@@ -636,11 +773,13 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
636
773
|
}
|
|
637
774
|
console.log('[validateProperty] Structure validation passed');
|
|
638
775
|
// If we have schema name and model name, validate against schema
|
|
639
|
-
console.log('[validateProperty] Checking schema validation:', { hasSchemaName: !!
|
|
640
|
-
if (
|
|
776
|
+
console.log('[validateProperty] Checking schema validation:', { hasSchemaName: !!fullContext._schemaName, hasModelName: !!fullContext.modelName });
|
|
777
|
+
if (fullContext._schemaName && fullContext.modelName) {
|
|
641
778
|
try {
|
|
642
|
-
console.log('[validateProperty] Creating schema instance:',
|
|
643
|
-
const schema = Schema.create(
|
|
779
|
+
console.log('[validateProperty] Creating schema instance:', fullContext._schemaName);
|
|
780
|
+
const schema = Schema.create(fullContext._schemaName, {
|
|
781
|
+
waitForReady: false,
|
|
782
|
+
});
|
|
644
783
|
const schemaSnapshot = schema.getService().getSnapshot();
|
|
645
784
|
const schemaStatus = schemaSnapshot.value;
|
|
646
785
|
console.log('[validateProperty] Schema status:', schemaStatus);
|
|
@@ -653,28 +792,28 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
653
792
|
if (schemaContext.models && Object.keys(schemaContext.models).length > 0) {
|
|
654
793
|
// If property name has changed, validate against the original name (from schema file)
|
|
655
794
|
// This handles the case where a property is renamed - the schema file still has the old name
|
|
656
|
-
const propertyNameToValidate =
|
|
657
|
-
?
|
|
658
|
-
:
|
|
795
|
+
const propertyNameToValidate = fullContext._originalValues?.name && fullContext._originalValues.name !== fullContext.name
|
|
796
|
+
? fullContext._originalValues.name
|
|
797
|
+
: fullContext.name || '';
|
|
659
798
|
console.log('[validateProperty] Validating against schema:', {
|
|
660
|
-
modelName:
|
|
799
|
+
modelName: fullContext.modelName,
|
|
661
800
|
propertyNameToValidate,
|
|
662
|
-
originalName:
|
|
663
|
-
currentName:
|
|
801
|
+
originalName: fullContext._originalValues?.name,
|
|
802
|
+
currentName: fullContext.name
|
|
664
803
|
});
|
|
665
|
-
const schemaResult = validationService.validateProperty(schemaContext,
|
|
804
|
+
const schemaResult = validationService.validateProperty(schemaContext, fullContext.modelName, propertyNameToValidate, fullContext);
|
|
666
805
|
console.log('[validateProperty] Schema validation result:', { isValid: schemaResult.isValid, errors: schemaResult.errors.length, errorCodes: schemaResult.errors.map(e => e.code) });
|
|
667
806
|
if (!schemaResult.isValid) {
|
|
668
807
|
// If property was renamed, some validation errors are expected (like property_not_found, missing_type)
|
|
669
808
|
// Only fail if it's a critical error that's not related to the rename
|
|
670
|
-
const isRenamed =
|
|
809
|
+
const isRenamed = fullContext._originalValues?.name && fullContext._originalValues.name !== fullContext.name;
|
|
671
810
|
const criticalErrors = schemaResult.errors.filter(err => {
|
|
672
811
|
// Allow property_not_found and missing_type errors when property is renamed
|
|
673
812
|
if (isRenamed && (err.code === 'property_not_found' || err.code === 'missing_type')) {
|
|
674
813
|
return false; // Not critical
|
|
675
814
|
}
|
|
676
815
|
// For non-renamed properties, only allow property_not_found if we're validating with the same name
|
|
677
|
-
if (err.code === 'property_not_found' && propertyNameToValidate ===
|
|
816
|
+
if (err.code === 'property_not_found' && propertyNameToValidate === fullContext.name) {
|
|
678
817
|
return false; // Not critical
|
|
679
818
|
}
|
|
680
819
|
return true; // Critical error
|
|
@@ -808,6 +947,15 @@ const modelPropertyMachine = xstate.setup({
|
|
|
808
947
|
}
|
|
809
948
|
newContext[key] = value;
|
|
810
949
|
}
|
|
950
|
+
// Preserve modelName and dataType from context or _originalValues so validation and savePropertyToDb
|
|
951
|
+
// never run with missing required/needed fields (e.g. when a just-created property is renamed before
|
|
952
|
+
// the full context is available from the creator).
|
|
953
|
+
if (newContext.modelName === undefined && context._originalValues?.modelName !== undefined) {
|
|
954
|
+
newContext.modelName = context._originalValues.modelName;
|
|
955
|
+
}
|
|
956
|
+
if (newContext.dataType === undefined && context._originalValues?.dataType !== undefined) {
|
|
957
|
+
newContext.dataType = context._originalValues.dataType;
|
|
958
|
+
}
|
|
811
959
|
// Compare with original values and set _isEdited flag (only for non-internal updates)
|
|
812
960
|
if (!onlyInternalFields && context._originalValues) {
|
|
813
961
|
const hasChanges = Object.keys(event).some((key) => {
|
|
@@ -877,6 +1025,23 @@ const modelPropertyMachine = xstate.setup({
|
|
|
877
1025
|
_schemaName: event.schemaName,
|
|
878
1026
|
})),
|
|
879
1027
|
},
|
|
1028
|
+
destroyStarted: {
|
|
1029
|
+
actions: xstate.assign({ _destroyInProgress: true, _destroyError: null }),
|
|
1030
|
+
},
|
|
1031
|
+
destroyDone: {
|
|
1032
|
+
actions: xstate.assign({ _destroyInProgress: false }),
|
|
1033
|
+
},
|
|
1034
|
+
destroyError: {
|
|
1035
|
+
actions: xstate.assign(({ event }) => ({
|
|
1036
|
+
_destroyInProgress: false,
|
|
1037
|
+
_destroyError: event.error instanceof Error
|
|
1038
|
+
? { message: event.error.message, name: event.error.name }
|
|
1039
|
+
: { message: String(event.error) },
|
|
1040
|
+
})),
|
|
1041
|
+
},
|
|
1042
|
+
clearDestroyError: {
|
|
1043
|
+
actions: xstate.assign({ _destroyError: null }),
|
|
1044
|
+
},
|
|
880
1045
|
},
|
|
881
1046
|
states: {
|
|
882
1047
|
idle: {
|
|
@@ -1002,6 +1167,32 @@ const modelPropertyMachine = xstate.setup({
|
|
|
1002
1167
|
},
|
|
1003
1168
|
});
|
|
1004
1169
|
|
|
1170
|
+
/**
|
|
1171
|
+
* Returns property rows for a model identified by modelFileId (model's schemaFileId).
|
|
1172
|
+
* Resolves modelFileId -> modelId via models table, then selects all properties where modelId = ?.
|
|
1173
|
+
* Each row includes schemaFileId for use with ModelProperty.createById(schemaFileId).
|
|
1174
|
+
*/
|
|
1175
|
+
const getModelPropertiesData = async (modelFileId) => {
|
|
1176
|
+
const appDb = main_cjs.BaseDb.getAppDb();
|
|
1177
|
+
if (!appDb || !modelFileId) {
|
|
1178
|
+
return [];
|
|
1179
|
+
}
|
|
1180
|
+
const modelRows = await appDb
|
|
1181
|
+
.select({ id: main_cjs.models.id })
|
|
1182
|
+
.from(main_cjs.models)
|
|
1183
|
+
.where(drizzleOrm.eq(main_cjs.models.schemaFileId, modelFileId))
|
|
1184
|
+
.limit(1);
|
|
1185
|
+
if (modelRows.length === 0) {
|
|
1186
|
+
return [];
|
|
1187
|
+
}
|
|
1188
|
+
const modelId = modelRows[0].id;
|
|
1189
|
+
const rows = await appDb
|
|
1190
|
+
.select()
|
|
1191
|
+
.from(main_cjs.properties)
|
|
1192
|
+
.where(drizzleOrm.eq(main_cjs.properties.modelId, modelId));
|
|
1193
|
+
return rows;
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1005
1196
|
const logger = debug('seedSdk:modelProperty:ModelProperty');
|
|
1006
1197
|
// Define the property keys from TProperty
|
|
1007
1198
|
const TPropertyKeys = [
|
|
@@ -1168,27 +1359,25 @@ class ModelProperty {
|
|
|
1168
1359
|
return fallbackIsEdited;
|
|
1169
1360
|
}
|
|
1170
1361
|
try {
|
|
1171
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
1172
|
-
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.schema; });
|
|
1173
1362
|
const { eq, and } = await import('drizzle-orm');
|
|
1174
|
-
const db = BaseDb.getAppDb();
|
|
1363
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
1175
1364
|
if (!db) {
|
|
1176
1365
|
return fallbackIsEdited;
|
|
1177
1366
|
}
|
|
1178
1367
|
// Find model by name
|
|
1179
1368
|
const modelRecords = await db
|
|
1180
|
-
.select({ id:
|
|
1181
|
-
.from(
|
|
1182
|
-
.where(eq(
|
|
1369
|
+
.select({ id: main_cjs.models.id })
|
|
1370
|
+
.from(main_cjs.models)
|
|
1371
|
+
.where(eq(main_cjs.models.name, property.modelName))
|
|
1183
1372
|
.limit(1);
|
|
1184
1373
|
if (modelRecords.length === 0) {
|
|
1185
1374
|
return fallbackIsEdited;
|
|
1186
1375
|
}
|
|
1187
1376
|
// Find property by name and modelId
|
|
1188
1377
|
const propertyRecords = await db
|
|
1189
|
-
.select({ isEdited:
|
|
1190
|
-
.from(
|
|
1191
|
-
.where(and(eq(
|
|
1378
|
+
.select({ isEdited: main_cjs.properties.isEdited })
|
|
1379
|
+
.from(main_cjs.properties)
|
|
1380
|
+
.where(and(eq(main_cjs.properties.name, property.name), eq(main_cjs.properties.modelId, modelRecords[0].id)))
|
|
1192
1381
|
.limit(1);
|
|
1193
1382
|
if (propertyRecords.length > 0) {
|
|
1194
1383
|
return propertyRecords[0].isEdited ?? false;
|
|
@@ -1209,18 +1398,15 @@ class ModelProperty {
|
|
|
1209
1398
|
return undefined;
|
|
1210
1399
|
}
|
|
1211
1400
|
try {
|
|
1212
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
1213
|
-
const seedSchema = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.schema; });
|
|
1214
|
-
const modelsTable = seedSchema.models;
|
|
1215
1401
|
const { eq } = await import('drizzle-orm');
|
|
1216
|
-
const db = BaseDb.getAppDb();
|
|
1402
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
1217
1403
|
if (!db) {
|
|
1218
1404
|
return undefined;
|
|
1219
1405
|
}
|
|
1220
1406
|
const refModelRecords = await db
|
|
1221
1407
|
.select()
|
|
1222
|
-
.from(
|
|
1223
|
-
.where(eq(
|
|
1408
|
+
.from(main_cjs.models)
|
|
1409
|
+
.where(eq(main_cjs.models.name, refModelName))
|
|
1224
1410
|
.limit(1);
|
|
1225
1411
|
if (refModelRecords.length > 0 && refModelRecords[0].id) {
|
|
1226
1412
|
return refModelRecords[0].id;
|
|
@@ -1241,8 +1427,8 @@ class ModelProperty {
|
|
|
1241
1427
|
return undefined;
|
|
1242
1428
|
}
|
|
1243
1429
|
try {
|
|
1244
|
-
const { Model } = await Promise.resolve().then(function () { return require('./index-
|
|
1245
|
-
const { modelPropertiesToObject } = await Promise.resolve().then(function () { return require('./index-
|
|
1430
|
+
const { Model } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.Model$1; });
|
|
1431
|
+
const { modelPropertiesToObject } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.model; });
|
|
1246
1432
|
const model = await Model.getByNameAsync(property.modelName);
|
|
1247
1433
|
if (!model || !model.properties || model.properties.length === 0) {
|
|
1248
1434
|
return undefined;
|
|
@@ -1291,22 +1477,17 @@ class ModelProperty {
|
|
|
1291
1477
|
// Try to get schema name from database first (more reliable)
|
|
1292
1478
|
if (this.modelId) {
|
|
1293
1479
|
try {
|
|
1294
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
1295
|
-
const seedSchema = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.schema; });
|
|
1296
|
-
const modelsTable = seedSchema.models;
|
|
1297
|
-
const modelSchemas = seedSchema.modelSchemas;
|
|
1298
|
-
const schemas = seedSchema.schemas;
|
|
1299
1480
|
const { eq } = await import('drizzle-orm');
|
|
1300
|
-
const db = BaseDb.getAppDb();
|
|
1481
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
1301
1482
|
if (db) {
|
|
1302
1483
|
const modelSchemaRecords = await db
|
|
1303
1484
|
.select({
|
|
1304
|
-
schemaName: schemas.name,
|
|
1485
|
+
schemaName: main_cjs.schemas.name,
|
|
1305
1486
|
})
|
|
1306
|
-
.from(modelSchemas)
|
|
1307
|
-
.innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id))
|
|
1308
|
-
.innerJoin(
|
|
1309
|
-
.where(eq(
|
|
1487
|
+
.from(main_cjs.modelSchemas)
|
|
1488
|
+
.innerJoin(main_cjs.schemas, eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
|
|
1489
|
+
.innerJoin(main_cjs.models, eq(main_cjs.modelSchemas.modelId, main_cjs.models.id))
|
|
1490
|
+
.where(eq(main_cjs.models.id, this.modelId))
|
|
1310
1491
|
.limit(1);
|
|
1311
1492
|
if (modelSchemaRecords.length > 0) {
|
|
1312
1493
|
schemaName = modelSchemaRecords[0].schemaName;
|
|
@@ -1344,10 +1525,12 @@ class ModelProperty {
|
|
|
1344
1525
|
schemaName,
|
|
1345
1526
|
});
|
|
1346
1527
|
}
|
|
1347
|
-
static create(property) {
|
|
1528
|
+
static create(property, options) {
|
|
1348
1529
|
if (!property) {
|
|
1349
1530
|
throw new Error('Property is required');
|
|
1350
1531
|
}
|
|
1532
|
+
const waitForReady = options?.waitForReady !== false;
|
|
1533
|
+
const readyTimeout = options?.readyTimeout ?? 5000;
|
|
1351
1534
|
// Debug: Log what's being passed to create()
|
|
1352
1535
|
console.log(`[ModelProperty.create] Input property data:`, JSON.stringify({
|
|
1353
1536
|
name: property.name,
|
|
@@ -1421,7 +1604,9 @@ class ModelProperty {
|
|
|
1421
1604
|
instance,
|
|
1422
1605
|
refCount: refCount + 1,
|
|
1423
1606
|
});
|
|
1424
|
-
|
|
1607
|
+
if (!waitForReady)
|
|
1608
|
+
return instance;
|
|
1609
|
+
return main_cjs.waitForEntityIdle(instance, { timeout: readyTimeout }).then(() => instance);
|
|
1425
1610
|
}
|
|
1426
1611
|
// Debug: Log what's being passed to the constructor
|
|
1427
1612
|
console.log(`[ModelProperty.create] propertyWithId before constructor:`, JSON.stringify({
|
|
@@ -1496,7 +1681,7 @@ class ModelProperty {
|
|
|
1496
1681
|
else if (typeof propertyWithId.modelId === 'string') {
|
|
1497
1682
|
// modelId is a string (modelFileId), need to convert to database ID
|
|
1498
1683
|
try {
|
|
1499
|
-
const { getModelIdByFileId } = await Promise.resolve().then(function () { return require('./index-
|
|
1684
|
+
const { getModelIdByFileId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
1500
1685
|
resolvedModelId = await getModelIdByFileId(propertyWithId.modelId);
|
|
1501
1686
|
logger(`Converted modelFileId "${propertyWithId.modelId}" to database modelId: ${resolvedModelId}`);
|
|
1502
1687
|
}
|
|
@@ -1509,7 +1694,7 @@ class ModelProperty {
|
|
|
1509
1694
|
// If we still don't have a modelId, try to resolve it from modelName
|
|
1510
1695
|
if (!resolvedModelId && propertyWithId.modelName) {
|
|
1511
1696
|
try {
|
|
1512
|
-
const { getModelId } = await Promise.resolve().then(function () { return require('./index-
|
|
1697
|
+
const { getModelId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
1513
1698
|
// Get schemaName from context if available
|
|
1514
1699
|
const schemaName = snapshot.context._schemaName;
|
|
1515
1700
|
resolvedModelId = await getModelId(propertyWithId.modelName, schemaName);
|
|
@@ -1583,7 +1768,9 @@ class ModelProperty {
|
|
|
1583
1768
|
// Start checking after a short delay to allow state machine to initialize
|
|
1584
1769
|
setTimeout(checkAndSend, 0);
|
|
1585
1770
|
}
|
|
1586
|
-
|
|
1771
|
+
if (!waitForReady)
|
|
1772
|
+
return proxiedInstance;
|
|
1773
|
+
return main_cjs.waitForEntityIdle(proxiedInstance, { timeout: readyTimeout }).then(() => proxiedInstance);
|
|
1587
1774
|
}
|
|
1588
1775
|
/**
|
|
1589
1776
|
* Get ModelProperty instance by propertyFileId from static cache
|
|
@@ -1616,10 +1803,8 @@ class ModelProperty {
|
|
|
1616
1803
|
return cachedInstance;
|
|
1617
1804
|
}
|
|
1618
1805
|
// Query database to get property data from ID
|
|
1619
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
1620
|
-
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-BmIVfqGN.js'); }).then(function (n) { return n.schema; });
|
|
1621
1806
|
const { eq } = await import('drizzle-orm');
|
|
1622
|
-
const db = BaseDb.getAppDb();
|
|
1807
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
1623
1808
|
console.log('db', !!db);
|
|
1624
1809
|
if (!db) {
|
|
1625
1810
|
console.log('db not found');
|
|
@@ -1627,13 +1812,13 @@ class ModelProperty {
|
|
|
1627
1812
|
}
|
|
1628
1813
|
const testRecords = await db
|
|
1629
1814
|
.select()
|
|
1630
|
-
.from(
|
|
1815
|
+
.from(main_cjs.properties)
|
|
1631
1816
|
.limit(100);
|
|
1632
1817
|
console.log('testRecords', testRecords);
|
|
1633
1818
|
const propertyRecords = await db
|
|
1634
1819
|
.select()
|
|
1635
|
-
.from(
|
|
1636
|
-
.where(eq(
|
|
1820
|
+
.from(main_cjs.properties)
|
|
1821
|
+
.where(eq(main_cjs.properties.schemaFileId, propertyFileId))
|
|
1637
1822
|
.limit(1);
|
|
1638
1823
|
console.log('propertyRecords', propertyRecords);
|
|
1639
1824
|
if (propertyRecords.length === 0) {
|
|
@@ -1642,9 +1827,9 @@ class ModelProperty {
|
|
|
1642
1827
|
const propertyRecord = propertyRecords[0];
|
|
1643
1828
|
// Get model name
|
|
1644
1829
|
const modelRecords = await db
|
|
1645
|
-
.select({ name:
|
|
1646
|
-
.from(
|
|
1647
|
-
.where(eq(
|
|
1830
|
+
.select({ name: main_cjs.models.name })
|
|
1831
|
+
.from(main_cjs.models)
|
|
1832
|
+
.where(eq(main_cjs.models.id, propertyRecord.modelId))
|
|
1648
1833
|
.limit(1);
|
|
1649
1834
|
if (modelRecords.length === 0) {
|
|
1650
1835
|
return undefined;
|
|
@@ -1667,17 +1852,17 @@ class ModelProperty {
|
|
|
1667
1852
|
// Get ref model name if applicable
|
|
1668
1853
|
if (propertyRecord.refModelId) {
|
|
1669
1854
|
const refModelRecords = await db
|
|
1670
|
-
.select({ name:
|
|
1671
|
-
.from(
|
|
1672
|
-
.where(eq(
|
|
1855
|
+
.select({ name: main_cjs.models.name })
|
|
1856
|
+
.from(main_cjs.models)
|
|
1857
|
+
.where(eq(main_cjs.models.id, propertyRecord.refModelId))
|
|
1673
1858
|
.limit(1);
|
|
1674
1859
|
if (refModelRecords.length > 0) {
|
|
1675
1860
|
propertyData.refModelName = refModelRecords[0].name;
|
|
1676
1861
|
propertyData.ref = refModelRecords[0].name;
|
|
1677
1862
|
}
|
|
1678
1863
|
}
|
|
1679
|
-
// Create ModelProperty instance
|
|
1680
|
-
const instance = this.create(propertyData);
|
|
1864
|
+
// Create ModelProperty instance (sync for createById so we can send updateContext)
|
|
1865
|
+
const instance = this.create(propertyData, { waitForReady: false });
|
|
1681
1866
|
// Set isEdited from database after creation
|
|
1682
1867
|
if (isEditedFromDb) {
|
|
1683
1868
|
instance._service.send({
|
|
@@ -1705,6 +1890,32 @@ class ModelProperty {
|
|
|
1705
1890
|
readyTimeout,
|
|
1706
1891
|
});
|
|
1707
1892
|
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Get all ModelProperty instances for a model.
|
|
1895
|
+
* Loads property rows from DB for the given modelFileId, creates instances via createById, optionally waits for idle.
|
|
1896
|
+
*/
|
|
1897
|
+
static async all(modelFileId, options) {
|
|
1898
|
+
const { waitForReady = false, readyTimeout = 5000 } = options ?? {};
|
|
1899
|
+
if (!modelFileId) {
|
|
1900
|
+
return [];
|
|
1901
|
+
}
|
|
1902
|
+
const rows = await getModelPropertiesData(modelFileId);
|
|
1903
|
+
const instances = [];
|
|
1904
|
+
for (const row of rows) {
|
|
1905
|
+
if (row.schemaFileId) {
|
|
1906
|
+
const instance = await this.createById(row.schemaFileId);
|
|
1907
|
+
if (instance) {
|
|
1908
|
+
instances.push(instance);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
if (waitForReady && instances.length > 0) {
|
|
1913
|
+
await Promise.all(instances.map((p) => main_cjs.waitForEntityIdle(p, {
|
|
1914
|
+
timeout: readyTimeout,
|
|
1915
|
+
})));
|
|
1916
|
+
}
|
|
1917
|
+
return instances;
|
|
1918
|
+
}
|
|
1708
1919
|
/**
|
|
1709
1920
|
* Track a pending write for a property
|
|
1710
1921
|
*/
|
|
@@ -1743,6 +1954,13 @@ class ModelProperty {
|
|
|
1743
1954
|
.filter(([_, write]) => write.modelId === modelId && write.status !== 'error')
|
|
1744
1955
|
.map(([propertyFileId]) => propertyFileId);
|
|
1745
1956
|
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Get modelId for a property that has a pending write (row may not be in DB yet).
|
|
1959
|
+
* Used to resolve modelName when validating a just-created property rename.
|
|
1960
|
+
*/
|
|
1961
|
+
static getPendingModelId(propertyFileId) {
|
|
1962
|
+
return this.pendingWrites.get(propertyFileId)?.modelId;
|
|
1963
|
+
}
|
|
1746
1964
|
getService() {
|
|
1747
1965
|
return this._service;
|
|
1748
1966
|
}
|
|
@@ -1849,6 +2067,61 @@ class ModelProperty {
|
|
|
1849
2067
|
// Service might already be stopped
|
|
1850
2068
|
}
|
|
1851
2069
|
}
|
|
2070
|
+
/**
|
|
2071
|
+
* Destroy the model property: remove from caches, delete from database, update Schema context, stop service.
|
|
2072
|
+
*/
|
|
2073
|
+
async destroy() {
|
|
2074
|
+
const context = this._getSnapshotContext();
|
|
2075
|
+
const cacheKey = context.modelName && context.name
|
|
2076
|
+
? `${context.modelName}:${context.name}`
|
|
2077
|
+
: (context.id ?? '');
|
|
2078
|
+
if (!cacheKey)
|
|
2079
|
+
return;
|
|
2080
|
+
main_cjs.forceRemoveFromCaches(this, {
|
|
2081
|
+
getCacheKeys: () => [cacheKey],
|
|
2082
|
+
caches: [ModelProperty.instanceCache],
|
|
2083
|
+
});
|
|
2084
|
+
await main_cjs.runDestroyLifecycle(this, {
|
|
2085
|
+
getService: (instance) => instance._service,
|
|
2086
|
+
doDestroy: async () => {
|
|
2087
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
2088
|
+
const schemaName = context._schemaName;
|
|
2089
|
+
const modelName = context.modelName;
|
|
2090
|
+
const propertyName = context.name;
|
|
2091
|
+
if (!modelName || !propertyName)
|
|
2092
|
+
return;
|
|
2093
|
+
if (db && schemaName) {
|
|
2094
|
+
const propertyRecords = await db
|
|
2095
|
+
.select({ propertyId: main_cjs.properties.id })
|
|
2096
|
+
.from(main_cjs.properties)
|
|
2097
|
+
.innerJoin(main_cjs.models, drizzleOrm.eq(main_cjs.properties.modelId, main_cjs.models.id))
|
|
2098
|
+
.innerJoin(main_cjs.modelSchemas, drizzleOrm.eq(main_cjs.models.id, main_cjs.modelSchemas.modelId))
|
|
2099
|
+
.innerJoin(main_cjs.schemas, drizzleOrm.eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
|
|
2100
|
+
.where(drizzleOrm.and(drizzleOrm.eq(main_cjs.schemas.name, schemaName), drizzleOrm.eq(main_cjs.models.name, modelName), drizzleOrm.eq(main_cjs.properties.name, propertyName)))
|
|
2101
|
+
.limit(1);
|
|
2102
|
+
if (propertyRecords.length > 0 && propertyRecords[0].propertyId != null) {
|
|
2103
|
+
await db
|
|
2104
|
+
.delete(main_cjs.properties)
|
|
2105
|
+
.where(drizzleOrm.eq(main_cjs.properties.id, propertyRecords[0].propertyId));
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
if (schemaName) {
|
|
2109
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-CV9hMg8m.js'); });
|
|
2110
|
+
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
2111
|
+
const snapshot = schema.getService().getSnapshot();
|
|
2112
|
+
const schemaContext = snapshot.context;
|
|
2113
|
+
if (schemaContext.models?.[modelName]?.properties?.[propertyName]) {
|
|
2114
|
+
const updatedModels = { ...schemaContext.models };
|
|
2115
|
+
const updatedProperties = { ...updatedModels[modelName].properties };
|
|
2116
|
+
delete updatedProperties[propertyName];
|
|
2117
|
+
updatedModels[modelName] = { ...updatedModels[modelName], properties: updatedProperties };
|
|
2118
|
+
schema.getService().send({ type: 'updateContext', models: updatedModels });
|
|
2119
|
+
schema.getService().send({ type: 'markAsDraft', propertyKey: `property:${modelName}:${propertyName}` });
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
},
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
1852
2125
|
}
|
|
1853
2126
|
ModelProperty.instanceCache = new Map();
|
|
1854
2127
|
// Pending writes tracking
|
|
@@ -1863,4 +2136,5 @@ exports.ModelProperty = ModelProperty;
|
|
|
1863
2136
|
exports.ModelProperty$1 = ModelProperty$1;
|
|
1864
2137
|
exports.convertPropertyToSchemaUpdate = convertPropertyToSchemaUpdate;
|
|
1865
2138
|
exports.updateModelProperties = updateModelProperties;
|
|
1866
|
-
|
|
2139
|
+
exports.writeFullSchemaNewVersion = writeFullSchemaNewVersion;
|
|
2140
|
+
//# sourceMappingURL=ModelProperty-BRKRREYP.js.map
|