@seedprotocol/sdk 0.4.9 → 0.4.11
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-sN5h2FvY.js → ArweaveClient-CwXE3NCK.js} +3 -3
- package/dist/{ArweaveClient-sN5h2FvY.js.map → ArweaveClient-CwXE3NCK.js.map} +1 -1
- package/dist/{ArweaveClient-DFqnm5Kj.js → ArweaveClient-DyhvHiIT.js} +3 -3
- package/dist/{ArweaveClient-DFqnm5Kj.js.map → ArweaveClient-DyhvHiIT.js.map} +1 -1
- package/dist/{Db-DIythELU.js → Db-Dr6gWq8d.js} +3 -3
- package/dist/{Db-DIythELU.js.map → Db-Dr6gWq8d.js.map} +1 -1
- package/dist/{Db-Dz17KxVs.js → Db-mH9nSDfI.js} +3 -3
- package/dist/{Db-Dz17KxVs.js.map → Db-mH9nSDfI.js.map} +1 -1
- package/dist/{EasClient-BadfcFDk.js → EasClient-Yh-t7zEA.js} +2 -2
- package/dist/{EasClient-DosbWaZN.js.map → EasClient-Yh-t7zEA.js.map} +1 -1
- package/dist/{EasClient-DosbWaZN.js → EasClient-aggdMFrc.js} +2 -2
- package/dist/{EasClient-BadfcFDk.js.map → EasClient-aggdMFrc.js.map} +1 -1
- package/dist/{FileManager-Wthr5yHO.js → FileManager-ClU_rIR0.js} +2 -2
- package/dist/{FileManager-Wthr5yHO.js.map → FileManager-ClU_rIR0.js.map} +1 -1
- package/dist/{FileManager-BHuVNWT3.js → FileManager-Dl2DD4Uc.js} +2 -2
- package/dist/{FileManager-BHuVNWT3.js.map → FileManager-Dl2DD4Uc.js.map} +1 -1
- package/dist/{ModelProperty-B9Z2DRxI.js → ModelProperty-gBmew8gY.js} +94 -18
- package/dist/ModelProperty-gBmew8gY.js.map +1 -0
- package/dist/{PathResolver-NEpTSgQK.js → PathResolver-CILJPhz1.js} +2 -2
- package/dist/{PathResolver-NEpTSgQK.js.map → PathResolver-CILJPhz1.js.map} +1 -1
- package/dist/{PathResolver-Cd1PZDLG.js → PathResolver-CfA_D3wa.js} +2 -2
- package/dist/{PathResolver-Cd1PZDLG.js.map → PathResolver-CfA_D3wa.js.map} +1 -1
- package/dist/{QueryClient-C9U8oZUe.js → QueryClient-BdpWYoxo.js} +2 -2
- package/dist/{QueryClient-C9U8oZUe.js.map → QueryClient-BdpWYoxo.js.map} +1 -1
- package/dist/{QueryClient-ndmA8MYL.js → QueryClient-Dl_P8u5s.js} +2 -2
- package/dist/{QueryClient-ndmA8MYL.js.map → QueryClient-Dl_P8u5s.js.map} +1 -1
- package/dist/{Schema-D1-HjT8z.js → Schema-B-vCLIuU.js} +21 -21
- package/dist/{Schema-D1-HjT8z.js.map → Schema-B-vCLIuU.js.map} +1 -1
- package/dist/{SchemaValidationService-CIXKzSpb.js → SchemaValidationService-C_iTQIjR.js} +2 -2
- package/dist/{SchemaValidationService-CIXKzSpb.js.map → SchemaValidationService-C_iTQIjR.js.map} +1 -1
- package/dist/cjs/{ModelProperty-09hNvSBl.js → ModelProperty-DcAM5M8T.js} +94 -18
- package/dist/cjs/ModelProperty-DcAM5M8T.js.map +1 -0
- package/dist/cjs/{Schema-BcwvUABB.js → Schema-B6ifYEhD.js} +20 -20
- package/dist/cjs/{Schema-BcwvUABB.js.map → Schema-B6ifYEhD.js.map} +1 -1
- package/dist/cjs/{SchemaValidationService-zty4nfCu.js → SchemaValidationService-OFyzZIUX.js} +2 -2
- package/dist/cjs/{SchemaValidationService-zty4nfCu.js.map → SchemaValidationService-OFyzZIUX.js.map} +1 -1
- package/dist/cjs/{getItem-Dlb5YSQn.js → getItem-CAYQYTpg.js} +2 -2
- package/dist/cjs/{getItem-Dlb5YSQn.js.map → getItem-CAYQYTpg.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-BqL06sEI.js → getPublishPayload-CBuGIazw.js} +5 -5
- package/dist/cjs/{getPublishPayload-BqL06sEI.js.map → getPublishPayload-CBuGIazw.js.map} +1 -1
- package/dist/cjs/{getPublishUploads-oukGI2N6.js → getPublishUploads-B7bB1OGg.js} +3 -3
- package/dist/cjs/{getPublishUploads-oukGI2N6.js.map → getPublishUploads-B7bB1OGg.js.map} +1 -1
- package/dist/cjs/{getSegmentedItemProperties-JT984OOp.js → getSegmentedItemProperties-MVZ-0mQG.js} +2 -2
- package/dist/cjs/{getSegmentedItemProperties-JT984OOp.js.map → getSegmentedItemProperties-MVZ-0mQG.js.map} +1 -1
- package/dist/cjs/{index-jubgGeM2.js → index-6P4MEsbO.js} +2 -2
- package/dist/cjs/index-6P4MEsbO.js.map +1 -0
- package/dist/cjs/{index-BLETlVgA.js → index-CA4i5TA7.js} +105 -46
- package/dist/cjs/index-CA4i5TA7.js.map +1 -0
- package/dist/cjs/{ownership-vfvyz3KJ.js → ownership-5TQ-v2CF.js} +2 -2
- package/dist/cjs/{ownership-vfvyz3KJ.js.map → ownership-5TQ-v2CF.js.map} +1 -1
- package/dist/{getItem-f9rNUz7I.js → getItem-xpxRXqHI.js} +2 -2
- package/dist/{getItem-f9rNUz7I.js.map → getItem-xpxRXqHI.js.map} +1 -1
- package/dist/{getPublishPayload-BBI_j9I2.js → getPublishPayload-CBeCMSeQ.js} +5 -5
- package/dist/{getPublishPayload-BBI_j9I2.js.map → getPublishPayload-CBeCMSeQ.js.map} +1 -1
- package/dist/{getPublishUploads-BFM94w5S.js → getPublishUploads-NITxWWDD.js} +3 -3
- package/dist/{getPublishUploads-BFM94w5S.js.map → getPublishUploads-NITxWWDD.js.map} +1 -1
- package/dist/{getSegmentedItemProperties-Di9vevKz.js → getSegmentedItemProperties-CYzNtJxH.js} +2 -2
- package/dist/{getSegmentedItemProperties-Di9vevKz.js.map → getSegmentedItemProperties-CYzNtJxH.js.map} +1 -1
- package/dist/{index-CSAVWKeA.js → index-BC0xKxkf.js} +3 -3
- package/dist/index-BC0xKxkf.js.map +1 -0
- package/dist/{index-j8WN8W6V.js → index-B_apqB1Q.js} +120 -61
- package/dist/index-B_apqB1Q.js.map +1 -0
- package/dist/{index-ajj6SHkh.js → index-CcXvJ2H7.js} +2 -2
- package/dist/index-CcXvJ2H7.js.map +1 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +11 -11
- package/dist/node.js +10 -10
- package/dist/{ownership-DLNI17NE.js → ownership-C7Afj3yr.js} +2 -2
- package/dist/{ownership-DLNI17NE.js.map → ownership-C7Afj3yr.js.map} +1 -1
- package/dist/{property-C6qoOzLG.js → property-C2gviIFJ.js} +4 -4
- package/dist/{property-C6qoOzLG.js.map → property-C2gviIFJ.js.map} +1 -1
- package/dist/{queries-jMaUn86w.js → queries-BFzkFn4Y.js} +2 -2
- package/dist/{queries-jMaUn86w.js.map → queries-BFzkFn4Y.js.map} +1 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts +5 -0
- package/dist/src/ModelProperty/ModelProperty.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/actors/validateProperty.d.ts.map +1 -1
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts.map +1 -1
- package/dist/src/helpers/db.d.ts.map +1 -1
- package/dist/src/services/write/actors/writeToDatabase.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/ModelProperty-B9Z2DRxI.js.map +0 -1
- package/dist/cjs/ModelProperty-09hNvSBl.js.map +0 -1
- package/dist/cjs/index-BLETlVgA.js.map +0 -1
- package/dist/cjs/index-jubgGeM2.js.map +0 -1
- package/dist/index-CSAVWKeA.js.map +0 -1
- package/dist/index-ajj6SHkh.js.map +0 -1
- package/dist/index-j8WN8W6V.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Value } from '@sinclair/typebox/value';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
import { a as ModelPropertyDataTypes, T as TPropertyDataType, c as TProperty } from './index-
|
|
3
|
+
import { a as ModelPropertyDataTypes, T as TPropertyDataType, c as TProperty } from './index-B_apqB1Q.js';
|
|
4
4
|
import 'pluralize';
|
|
5
5
|
import 'drizzle-orm';
|
|
6
6
|
import { Type } from '@sinclair/typebox';
|
|
@@ -651,4 +651,4 @@ class SchemaValidationService {
|
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
export { SchemaValidationService };
|
|
654
|
-
//# sourceMappingURL=SchemaValidationService-
|
|
654
|
+
//# sourceMappingURL=SchemaValidationService-C_iTQIjR.js.map
|
package/dist/{SchemaValidationService-CIXKzSpb.js.map → SchemaValidationService-C_iTQIjR.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaValidationService-CIXKzSpb.js","sources":["../../src/Schema/service/validation/SchemaValidationService.ts"],"sourcesContent":["import { Value } from '@sinclair/typebox/value'\nimport { TProperty } from '@/Schema'\nimport { ModelPropertyDataTypes, TPropertyDataType } from '@/helpers/property'\nimport { ValidationResult, ValidationError, ValidationRules } from '@/Schema/validation'\nimport { SchemaMachineContext } from '../schemaMachine'\nimport { ModelPropertyMachineContext } from '@/ModelProperty/service/modelPropertyMachine'\nimport { ModelMachineContext } from '@/Model/service/modelMachine'\nimport { Type, TSchema, TUnion, TLiteral } from '@sinclair/typebox'\nimport debug from 'debug'\n\nconst logger = debug('seedSdk:schema:validation')\n\n/**\n * Service for validating schemas, models, and properties using TypeBox\n */\nexport class SchemaValidationService {\n /**\n * Enhance TypeBox error message with expected values for union/literal types\n */\n private enhanceErrorMessage(\n error: any,\n schema: TSchema,\n fieldPath: string\n ): string {\n const originalMessage = error.message || 'Validation failed'\n \n // Handle Union type errors (like TPropertyDataType)\n if (error.type === 'Union' || originalMessage.includes('union')) {\n const expectedValues = this.extractExpectedValues(schema, fieldPath)\n if (expectedValues.length > 0) {\n return `Expected one of: ${expectedValues.join(', ')}. Received: ${JSON.stringify(error.value)}`\n }\n }\n \n // Handle Literal type errors\n if (error.type === 'Literal') {\n const expectedValue = this.extractLiteralValue(schema, fieldPath)\n if (expectedValue !== undefined) {\n return `Expected: ${JSON.stringify(expectedValue)}. Received: ${JSON.stringify(error.value)}`\n }\n }\n \n // Return enhanced message with value info if available\n if (error.value !== undefined) {\n return `${originalMessage}. Received: ${JSON.stringify(error.value)}`\n }\n \n return originalMessage\n }\n\n /**\n * Extract expected values from a schema for a given field path\n */\n private extractExpectedValues(schema: TSchema | null, fieldPath: string): string[] {\n try {\n // Handle TProperty schema - check if this is the dataType field\n if (fieldPath === '/dataType' || fieldPath.endsWith('/dataType')) {\n // Return all ModelPropertyDataTypes enum values\n return Object.values(ModelPropertyDataTypes) as string[]\n }\n \n // Handle TStorageType\n if (fieldPath === '/storageType' || fieldPath.endsWith('/storageType')) {\n return ['ItemStorage', 'PropertyStorage']\n }\n \n // If we have a schema, try to extract from it\n if (!schema) {\n return []\n }\n \n // Try to extract from TypeBox Union type using the schema directly\n const schemaObj = schema as any\n const kind = schemaObj[Symbol.for('TypeBox.Kind')]\n \n if (kind === 'Union') {\n const union = schemaObj as TUnion<any>\n const anyOf = union.anyOf || []\n const values: string[] = []\n \n for (const item of anyOf) {\n const itemKind = item?.[Symbol.for('TypeBox.Kind')]\n if (itemKind === 'Literal') {\n const literal = item as TLiteral<any>\n if (literal.const !== undefined) {\n values.push(String(literal.const))\n }\n }\n }\n \n if (values.length > 0) {\n return values\n }\n }\n \n // Fallback: try to extract from JSON schema format\n if (typeof schema === 'object' && 'anyOf' in schema) {\n const union = schema as any\n if (Array.isArray(union.anyOf)) {\n return union.anyOf\n .map((item: any) => {\n if (item.const !== undefined) return String(item.const)\n if (item.enum && Array.isArray(item.enum)) return item.enum.map(String)\n return null\n })\n .filter((val: any) => val !== null)\n .flat()\n .map(String)\n }\n }\n } catch (error) {\n logger('Error extracting expected values:', error)\n }\n \n return []\n }\n\n /**\n * Extract literal value from a schema\n */\n private extractLiteralValue(schema: TSchema, fieldPath: string): any {\n try {\n if (schema && typeof schema === 'object') {\n const schemaObj = schema as any\n if (schemaObj[Symbol.for('TypeBox.Kind')] === 'Literal') {\n return (schemaObj as TLiteral<any>).const\n }\n if (schemaObj.const !== undefined) {\n return schemaObj.const\n }\n }\n } catch (error) {\n logger('Error extracting literal value:', error)\n }\n \n return undefined\n }\n\n /**\n * Get the schema for a specific field path\n */\n private getSchemaForField(schema: TSchema, fieldPath: string): TSchema | null {\n try {\n if (!schema || typeof schema !== 'object') return null\n \n // Remove leading slash\n const path = fieldPath.replace(/^\\//, '')\n if (!path) return schema\n \n const schemaObj = schema as any\n const kind = schemaObj[Symbol.for('TypeBox.Kind')]\n \n // For TProperty (Object type), check properties\n if (kind === 'Object') {\n const properties = schemaObj.properties\n if (properties && properties[path]) {\n return properties[path]\n }\n }\n \n // Special handling for known fields - return the actual schema\n if (path === 'dataType') {\n return TPropertyDataType as TSchema\n }\n \n // Fallback: check if schema has the property\n if (path in schemaObj) {\n return schemaObj[path]\n }\n } catch (error) {\n logger('Error getting schema for field:', error)\n }\n \n return null\n }\n\n /**\n * Validate a property structure against TProperty schema\n */\n validatePropertyStructure(\n property: ModelPropertyMachineContext\n ): ValidationResult {\n try {\n const isValid = Value.Check(TProperty, property)\n \n const errors: ValidationError[] = []\n \n if (!isValid) {\n const typeBoxErrors = [...Value.Errors(TProperty, property)]\n errors.push(...typeBoxErrors.map(err => {\n const fieldPath = err.path || 'unknown'\n const fieldSchema = this.getSchemaForField(TProperty, fieldPath)\n const enhancedMessage = this.enhanceErrorMessage(err, fieldSchema || TProperty, fieldPath)\n \n return {\n field: fieldPath,\n message: enhancedMessage,\n code: String(err.type || 'validation_error'),\n severity: 'error' as const,\n }\n }))\n }\n \n // Non-List types: refValueType is only valid for Relation+Image (related entity type). Reject otherwise.\n const nonListTypes = [\n ModelPropertyDataTypes.Text,\n ModelPropertyDataTypes.Number,\n ModelPropertyDataTypes.Boolean,\n ModelPropertyDataTypes.Date,\n ModelPropertyDataTypes.Json,\n ModelPropertyDataTypes.Image,\n ModelPropertyDataTypes.File,\n ModelPropertyDataTypes.Html,\n ModelPropertyDataTypes.Relation,\n ]\n if (nonListTypes.includes(property.dataType as ModelPropertyDataTypes)) {\n const hasRefValueType = property.refValueType != null && String(property.refValueType).trim() !== ''\n if (hasRefValueType) {\n // Relation may keep refValueType only for Image (relation to Image entity)\n if (property.dataType === ModelPropertyDataTypes.Relation && property.refValueType === ModelPropertyDataTypes.Image) {\n // Allowed: Relation to Image\n } else {\n errors.push({\n field: 'refValueType',\n message: `refValueType is only valid for List properties. Use dataType 'List' with refValueType '${property.refValueType}' for lists of ${property.refValueType}.`,\n code: 'invalid_ref_value_type',\n severity: 'error' as const,\n })\n }\n }\n }\n\n // List: refValueType is required\n if (property.dataType === ModelPropertyDataTypes.List) {\n const hasRefValueType = property.refValueType != null && String(property.refValueType).trim() !== ''\n if (!hasRefValueType) {\n errors.push({\n field: 'refValueType',\n message: `List properties require refValueType (e.g. 'Text', 'Number', 'Relation') to specify the element type.`,\n code: 'missing_ref_value_type',\n severity: 'error' as const,\n })\n }\n // List of relations: ref is required\n if (hasRefValueType && property.refValueType === ModelPropertyDataTypes.Relation) {\n const hasRef = property.ref && property.ref.trim() !== ''\n const hasRefModelName = property.refModelName && property.refModelName.trim() !== ''\n const hasRefModelId = property.refModelId !== undefined && property.refModelId !== null\n if (!hasRef && !hasRefModelName && !hasRefModelId) {\n errors.push({\n field: 'ref',\n message: `List properties with refValueType 'Relation' require either a \"ref\", \"refModelName\", or \"refModelId\" field to be defined`,\n code: 'missing_ref',\n severity: 'error' as const,\n })\n }\n }\n }\n\n // Relation (single): ref is required\n if (property.dataType === ModelPropertyDataTypes.Relation) {\n const hasRef = property.ref && property.ref.trim() !== ''\n const hasRefModelName = property.refModelName && property.refModelName.trim() !== ''\n const hasRefModelId = property.refModelId !== undefined && property.refModelId !== null\n if (!hasRef && !hasRefModelName && !hasRefModelId) {\n errors.push({\n field: 'ref',\n message: `Property with dataType \"Relation\" requires either a \"ref\", \"refModelName\", or \"refModelId\" field to be defined`,\n code: 'missing_ref',\n severity: 'error' as const,\n })\n }\n if ((hasRef || hasRefModelName) && !hasRefModelId) {\n logger(`Property \"${property.name}\" has ref/refModelName but no refModelId - will be resolved asynchronously`)\n }\n }\n \n return {\n isValid: errors.length === 0,\n errors,\n }\n } catch (error) {\n logger('Error validating property structure:', error)\n return {\n isValid: false,\n errors: [{\n field: 'property',\n message: error instanceof Error ? error.message : 'Unknown validation error',\n code: 'validation_exception',\n severity: 'error' as const,\n }],\n }\n }\n }\n\n /**\n * Validate a property value against its validation rules\n */\n validatePropertyValue(\n value: any,\n dataType: ModelPropertyDataTypes,\n validationRules?: ValidationRules\n ): ValidationResult {\n const errors: ValidationError[] = []\n const warnings: ValidationError[] = []\n\n try {\n // Array values are only allowed for List properties\n if (dataType !== ModelPropertyDataTypes.List && Array.isArray(value)) {\n errors.push({\n field: 'value',\n message: 'Array values are only allowed for List properties. Use dataType \"List\" with refValueType to store multiple values.',\n code: 'array_not_allowed',\n severity: 'error' as const,\n })\n }\n\n // Build base TypeBox schema from dataType\n let schema: TSchema = this.getBaseSchemaForDataType(dataType)\n\n // Apply validation rules\n if (validationRules) {\n schema = this.applyValidationRules(schema, dataType, validationRules)\n }\n\n // Validate using TypeBox\n const isValid = Value.Check(schema, value)\n \n if (!isValid) {\n const typeBoxErrors = [...Value.Errors(schema, value)]\n errors.push(...typeBoxErrors.map(err => {\n const fieldPath = err.path || 'value'\n const enhancedMessage = this.enhanceErrorMessage(err, schema, fieldPath)\n \n return {\n field: fieldPath,\n message: enhancedMessage,\n code: String(err.type || 'value_validation_error'),\n severity: 'error' as const,\n }\n }))\n }\n\n // Additional custom validations\n if (validationRules) {\n const customErrors = this.validateCustomRules(value, validationRules)\n errors.push(...customErrors)\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n logger('Error validating property value:', error)\n return {\n isValid: false,\n errors: [{\n field: 'value',\n message: error instanceof Error ? error.message : 'Unknown validation error',\n code: 'validation_exception',\n severity: 'error' as const,\n }],\n }\n }\n }\n\n /**\n * Validate a specific property within a schema\n */\n validateProperty(\n schema: SchemaMachineContext,\n modelName: string,\n propertyName: string,\n propertyData?: ModelPropertyMachineContext\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n // Check if model exists\n if (!schema.models || !schema.models[modelName]) {\n errors.push({\n field: 'model',\n message: `Model \"${modelName}\" not found in schema`,\n code: 'model_not_found',\n severity: 'error' as const,\n })\n return { isValid: false, errors }\n }\n\n const model = schema.models[modelName]\n\n // Check if property exists in model\n // If the property name has changed (renamed), check if the original name exists\n let propertyDefinition = model.properties?.[propertyName]\n let actualPropertyName = propertyName\n \n if (!propertyDefinition && propertyData?._originalValues?.name) {\n const originalName = propertyData._originalValues.name\n // If the current name differs from the original, check if original exists\n if (originalName !== propertyName && model.properties?.[originalName]) {\n propertyDefinition = model.properties[originalName]\n actualPropertyName = originalName\n // Property is being renamed, which is allowed - continue validation\n }\n }\n \n if (!propertyDefinition) {\n errors.push({\n field: 'property',\n message: `Property \"${propertyName}\" not found in model \"${modelName}\"`,\n code: 'property_not_found',\n severity: 'error' as const,\n })\n return { isValid: false, errors }\n }\n\n // If propertyData is provided, validate its structure\n if (propertyData) {\n const structureResult = this.validatePropertyStructure(propertyData)\n errors.push(...structureResult.errors)\n }\n\n // Validate property definition structure\n if (!propertyDefinition.type) {\n errors.push({\n field: 'property.type',\n message: 'Property type is required',\n code: 'missing_type',\n severity: 'error' as const,\n })\n }\n\n // Validate Relation: requires model\n if (propertyDefinition.type === 'Relation') {\n if (!propertyDefinition.model || propertyDefinition.model.trim() === '') {\n errors.push({\n field: 'property.model',\n message: `Property with type \"Relation\" requires a \"model\" field to be defined`,\n code: 'missing_ref',\n severity: 'error' as const,\n })\n } else if (!schema.models[propertyDefinition.model]) {\n errors.push({\n field: 'property.model',\n message: `Referenced model \"${propertyDefinition.model}\" not found in schema`,\n code: 'invalid_reference',\n severity: 'error' as const,\n })\n }\n }\n\n // Validate List: requires items with type; model required only when items.type === 'Relation'\n if (propertyDefinition.type === 'List') {\n const items = (propertyDefinition as any).items\n if (!items || !items.type) {\n errors.push({\n field: 'property.items',\n message: 'List properties require \"items\" with \"type\" (e.g. items: { type: \"Text\" } or items: { type: \"Relation\", model: \"Tag\" })',\n code: 'missing_items',\n severity: 'error' as const,\n })\n } else if (items.type === 'Relation' || items.type === 'RelationProperty') {\n const model = items.model || propertyDefinition.model\n if (!model || String(model).trim() === '') {\n errors.push({\n field: 'property.items.model',\n message: 'List of relations requires \"items.model\" to specify the related model',\n code: 'missing_ref',\n severity: 'error' as const,\n })\n } else if (schema.models && !schema.models[model]) {\n errors.push({\n field: 'property.items.model',\n message: `Referenced model \"${model}\" not found in schema`,\n code: 'invalid_reference',\n severity: 'error' as const,\n })\n }\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Validate model structure (basic structure checks)\n */\n validateModelStructure(\n model: ModelMachineContext & { properties?: { [key: string]: any } }\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n // Validate model name\n if (!model.modelName || model.modelName.trim() === '') {\n errors.push({\n field: 'modelName',\n message: 'Model name is required',\n code: 'missing_model_name',\n severity: 'error' as const,\n })\n }\n\n // Validate schema name\n if (!model.schemaName || model.schemaName.trim() === '') {\n errors.push({\n field: 'schemaName',\n message: 'Schema name is required',\n code: 'missing_schema_name',\n severity: 'error' as const,\n })\n }\n\n // Validate properties is an object\n if (model.properties && typeof model.properties !== 'object') {\n errors.push({\n field: 'properties',\n message: 'Properties must be an object',\n code: 'invalid_properties',\n severity: 'error' as const,\n })\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Validate a model against a schema WITHOUT requiring it to be in the schema's context\n * This allows validation before registration, preventing update loops\n */\n validateModelAgainstSchema(\n schema: SchemaMachineContext,\n modelName: string,\n modelData: ModelMachineContext & { properties?: { [key: string]: any } }\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n // Create a temporary schema context that includes this model for validation purposes\n // This allows validateProperty to work without actually adding the model to the real schema\n const tempSchemaContext: SchemaMachineContext = {\n ...schema,\n models: {\n ...schema.models,\n [modelName]: {\n properties: modelData.properties || {},\n },\n },\n }\n\n // Use validateModel which now works because the model is in the temp context\n return this.validateModel(tempSchemaContext, modelName, modelData)\n }\n\n /**\n * Validate a model within a schema (requires model to already be in schema context)\n */\n validateModel(\n schema: SchemaMachineContext,\n modelName: string,\n modelData?: ModelMachineContext\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n if (!schema.models || !schema.models[modelName]) {\n errors.push({\n field: 'model',\n message: `Model \"${modelName}\" not found in schema`,\n code: 'model_not_found',\n severity: 'error' as const,\n })\n return { isValid: false, errors }\n }\n\n const model = schema.models[modelName]\n\n // Validate all properties in the model\n if (model.properties) {\n for (const [propertyName, propertyDef] of Object.entries(model.properties)) {\n const propertyResult = this.validateProperty(schema, modelName, propertyName)\n if (!propertyResult.isValid) {\n errors.push(...propertyResult.errors.map(err => ({\n ...err,\n field: `${modelName}.${propertyName}.${err.field}`,\n })))\n }\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Validate entire schema\n */\n validateSchema(schema: SchemaMachineContext): ValidationResult {\n const errors: ValidationError[] = []\n\n // Validate schema name\n if (!schema.schemaName || schema.schemaName.trim() === '') {\n errors.push({\n field: 'schemaName',\n message: 'Schema name is required',\n code: 'missing_schema_name',\n severity: 'error' as const,\n })\n }\n\n // Validate metadata\n if (!schema.metadata) {\n errors.push({\n field: 'metadata',\n message: 'Schema metadata is required',\n code: 'missing_metadata',\n severity: 'error' as const,\n })\n } else {\n if (!schema.metadata.name || schema.metadata.name.trim() === '') {\n errors.push({\n field: 'metadata.name',\n message: 'Schema metadata name is required',\n code: 'missing_metadata_name',\n severity: 'error' as const,\n })\n }\n }\n\n // Validate models if they exist\n if (schema.models && Object.keys(schema.models).length > 0) {\n // Validate each model\n for (const modelName of Object.keys(schema.models)) {\n const modelResult = this.validateModel(schema, modelName)\n if (!modelResult.isValid) {\n errors.push(...modelResult.errors)\n }\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Get base TypeBox schema for a data type\n */\n private getBaseSchemaForDataType(dataType: ModelPropertyDataTypes): TSchema {\n switch (dataType) {\n case ModelPropertyDataTypes.Text:\n case ModelPropertyDataTypes.Html:\n return Type.String()\n case ModelPropertyDataTypes.Number:\n return Type.Number()\n case ModelPropertyDataTypes.Boolean:\n return Type.Boolean()\n case ModelPropertyDataTypes.Date:\n return Type.String({ format: 'date-time' })\n case ModelPropertyDataTypes.Json:\n return Type.Any()\n case ModelPropertyDataTypes.List:\n return Type.Array(Type.Any())\n case ModelPropertyDataTypes.Relation:\n case ModelPropertyDataTypes.Image:\n case ModelPropertyDataTypes.File:\n return Type.Union([Type.String(), Type.Null()])\n default:\n return Type.Any()\n }\n }\n\n /**\n * Apply validation rules to a TypeBox schema\n */\n private applyValidationRules(\n schema: TSchema,\n dataType: ModelPropertyDataTypes,\n rules: ValidationRules\n ): TSchema {\n let result = schema\n\n // Apply pattern (regex) for strings\n if (rules.pattern && (dataType === ModelPropertyDataTypes.Text || dataType === ModelPropertyDataTypes.Html)) {\n try {\n const regex = new RegExp(rules.pattern)\n result = Type.RegExp(regex)\n } catch (error) {\n logger('Invalid regex pattern:', rules.pattern, error)\n }\n }\n\n // Apply minLength/maxLength for strings\n if (dataType === ModelPropertyDataTypes.Text || dataType === ModelPropertyDataTypes.Html) {\n const stringSchema = Type.String()\n if (rules.minLength !== undefined) {\n result = Type.String({ minLength: rules.minLength })\n }\n if (rules.maxLength !== undefined) {\n if (rules.minLength !== undefined) {\n result = Type.String({ minLength: rules.minLength, maxLength: rules.maxLength })\n } else {\n result = Type.String({ maxLength: rules.maxLength })\n }\n }\n }\n\n // Apply enum\n if (rules.enum && Array.isArray(rules.enum) && rules.enum.length > 0) {\n result = Type.Union(rules.enum.map(val => Type.Literal(val)))\n }\n\n return result\n }\n\n /**\n * Validate custom validation rules\n */\n private validateCustomRules(\n value: any,\n rules: ValidationRules\n ): ValidationError[] {\n const errors: ValidationError[] = []\n\n // Custom validator reference (would need to be implemented based on your needs)\n if (rules.custom) {\n // TODO: Implement custom validator lookup and execution\n logger('Custom validator not yet implemented:', rules.custom)\n }\n\n return errors\n }\n}\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAUA,MAAM,MAAM,GAAG,KAAK,CAAC,2BAA2B,CAAC;AAEjD;;AAEG;MACU,uBAAuB,CAAA;AAClC;;AAEG;AACK,IAAA,mBAAmB,CACzB,KAAU,EACV,MAAe,EACf,SAAiB,EAAA;AAEjB,QAAA,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,IAAI,mBAAmB;;AAG5D,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC/D,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,SAAS,CAAC;AACpE,YAAA,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;AAC7B,gBAAA,OAAO,oBAAoB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,YAAA,EAAe,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAClG;QACF;;AAGA,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;YAC5B,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC;AACjE,YAAA,IAAI,aAAa,KAAK,SAAS,EAAE;AAC/B,gBAAA,OAAO,aAAa,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA,YAAA,EAAe,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC/F;QACF;;AAGA,QAAA,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;AAC7B,YAAA,OAAO,CAAA,EAAG,eAAe,CAAA,YAAA,EAAe,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK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KAAK,CAAC,MAAM,CAAC;QAC/D;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"SchemaValidationService-C_iTQIjR.js","sources":["../../src/Schema/service/validation/SchemaValidationService.ts"],"sourcesContent":["import { Value } from '@sinclair/typebox/value'\nimport { TProperty } from '@/Schema'\nimport { ModelPropertyDataTypes, TPropertyDataType } from '@/helpers/property'\nimport { ValidationResult, ValidationError, ValidationRules } from '@/Schema/validation'\nimport { SchemaMachineContext } from '../schemaMachine'\nimport { ModelPropertyMachineContext } from '@/ModelProperty/service/modelPropertyMachine'\nimport { ModelMachineContext } from '@/Model/service/modelMachine'\nimport { Type, TSchema, TUnion, TLiteral } from '@sinclair/typebox'\nimport debug from 'debug'\n\nconst logger = debug('seedSdk:schema:validation')\n\n/**\n * Service for validating schemas, models, and properties using TypeBox\n */\nexport class SchemaValidationService {\n /**\n * Enhance TypeBox error message with expected values for union/literal types\n */\n private enhanceErrorMessage(\n error: any,\n schema: TSchema,\n fieldPath: string\n ): string {\n const originalMessage = error.message || 'Validation failed'\n \n // Handle Union type errors (like TPropertyDataType)\n if (error.type === 'Union' || originalMessage.includes('union')) {\n const expectedValues = this.extractExpectedValues(schema, fieldPath)\n if (expectedValues.length > 0) {\n return `Expected one of: ${expectedValues.join(', ')}. Received: ${JSON.stringify(error.value)}`\n }\n }\n \n // Handle Literal type errors\n if (error.type === 'Literal') {\n const expectedValue = this.extractLiteralValue(schema, fieldPath)\n if (expectedValue !== undefined) {\n return `Expected: ${JSON.stringify(expectedValue)}. Received: ${JSON.stringify(error.value)}`\n }\n }\n \n // Return enhanced message with value info if available\n if (error.value !== undefined) {\n return `${originalMessage}. Received: ${JSON.stringify(error.value)}`\n }\n \n return originalMessage\n }\n\n /**\n * Extract expected values from a schema for a given field path\n */\n private extractExpectedValues(schema: TSchema | null, fieldPath: string): string[] {\n try {\n // Handle TProperty schema - check if this is the dataType field\n if (fieldPath === '/dataType' || fieldPath.endsWith('/dataType')) {\n // Return all ModelPropertyDataTypes enum values\n return Object.values(ModelPropertyDataTypes) as string[]\n }\n \n // Handle TStorageType\n if (fieldPath === '/storageType' || fieldPath.endsWith('/storageType')) {\n return ['ItemStorage', 'PropertyStorage']\n }\n \n // If we have a schema, try to extract from it\n if (!schema) {\n return []\n }\n \n // Try to extract from TypeBox Union type using the schema directly\n const schemaObj = schema as any\n const kind = schemaObj[Symbol.for('TypeBox.Kind')]\n \n if (kind === 'Union') {\n const union = schemaObj as TUnion<any>\n const anyOf = union.anyOf || []\n const values: string[] = []\n \n for (const item of anyOf) {\n const itemKind = item?.[Symbol.for('TypeBox.Kind')]\n if (itemKind === 'Literal') {\n const literal = item as TLiteral<any>\n if (literal.const !== undefined) {\n values.push(String(literal.const))\n }\n }\n }\n \n if (values.length > 0) {\n return values\n }\n }\n \n // Fallback: try to extract from JSON schema format\n if (typeof schema === 'object' && 'anyOf' in schema) {\n const union = schema as any\n if (Array.isArray(union.anyOf)) {\n return union.anyOf\n .map((item: any) => {\n if (item.const !== undefined) return String(item.const)\n if (item.enum && Array.isArray(item.enum)) return item.enum.map(String)\n return null\n })\n .filter((val: any) => val !== null)\n .flat()\n .map(String)\n }\n }\n } catch (error) {\n logger('Error extracting expected values:', error)\n }\n \n return []\n }\n\n /**\n * Extract literal value from a schema\n */\n private extractLiteralValue(schema: TSchema, fieldPath: string): any {\n try {\n if (schema && typeof schema === 'object') {\n const schemaObj = schema as any\n if (schemaObj[Symbol.for('TypeBox.Kind')] === 'Literal') {\n return (schemaObj as TLiteral<any>).const\n }\n if (schemaObj.const !== undefined) {\n return schemaObj.const\n }\n }\n } catch (error) {\n logger('Error extracting literal value:', error)\n }\n \n return undefined\n }\n\n /**\n * Get the schema for a specific field path\n */\n private getSchemaForField(schema: TSchema, fieldPath: string): TSchema | null {\n try {\n if (!schema || typeof schema !== 'object') return null\n \n // Remove leading slash\n const path = fieldPath.replace(/^\\//, '')\n if (!path) return schema\n \n const schemaObj = schema as any\n const kind = schemaObj[Symbol.for('TypeBox.Kind')]\n \n // For TProperty (Object type), check properties\n if (kind === 'Object') {\n const properties = schemaObj.properties\n if (properties && properties[path]) {\n return properties[path]\n }\n }\n \n // Special handling for known fields - return the actual schema\n if (path === 'dataType') {\n return TPropertyDataType as TSchema\n }\n \n // Fallback: check if schema has the property\n if (path in schemaObj) {\n return schemaObj[path]\n }\n } catch (error) {\n logger('Error getting schema for field:', error)\n }\n \n return null\n }\n\n /**\n * Validate a property structure against TProperty schema\n */\n validatePropertyStructure(\n property: ModelPropertyMachineContext\n ): ValidationResult {\n try {\n const isValid = Value.Check(TProperty, property)\n \n const errors: ValidationError[] = []\n \n if (!isValid) {\n const typeBoxErrors = [...Value.Errors(TProperty, property)]\n errors.push(...typeBoxErrors.map(err => {\n const fieldPath = err.path || 'unknown'\n const fieldSchema = this.getSchemaForField(TProperty, fieldPath)\n const enhancedMessage = this.enhanceErrorMessage(err, fieldSchema || TProperty, fieldPath)\n \n return {\n field: fieldPath,\n message: enhancedMessage,\n code: String(err.type || 'validation_error'),\n severity: 'error' as const,\n }\n }))\n }\n \n // Non-List types: refValueType is only valid for Relation+Image (related entity type). Reject otherwise.\n const nonListTypes = [\n ModelPropertyDataTypes.Text,\n ModelPropertyDataTypes.Number,\n ModelPropertyDataTypes.Boolean,\n ModelPropertyDataTypes.Date,\n ModelPropertyDataTypes.Json,\n ModelPropertyDataTypes.Image,\n ModelPropertyDataTypes.File,\n ModelPropertyDataTypes.Html,\n ModelPropertyDataTypes.Relation,\n ]\n if (nonListTypes.includes(property.dataType as ModelPropertyDataTypes)) {\n const hasRefValueType = property.refValueType != null && String(property.refValueType).trim() !== ''\n if (hasRefValueType) {\n // Relation may keep refValueType only for Image (relation to Image entity)\n if (property.dataType === ModelPropertyDataTypes.Relation && property.refValueType === ModelPropertyDataTypes.Image) {\n // Allowed: Relation to Image\n } else {\n errors.push({\n field: 'refValueType',\n message: `refValueType is only valid for List properties. Use dataType 'List' with refValueType '${property.refValueType}' for lists of ${property.refValueType}.`,\n code: 'invalid_ref_value_type',\n severity: 'error' as const,\n })\n }\n }\n }\n\n // List: refValueType is required\n if (property.dataType === ModelPropertyDataTypes.List) {\n const hasRefValueType = property.refValueType != null && String(property.refValueType).trim() !== ''\n if (!hasRefValueType) {\n errors.push({\n field: 'refValueType',\n message: `List properties require refValueType (e.g. 'Text', 'Number', 'Relation') to specify the element type.`,\n code: 'missing_ref_value_type',\n severity: 'error' as const,\n })\n }\n // List of relations: ref is required\n if (hasRefValueType && property.refValueType === ModelPropertyDataTypes.Relation) {\n const hasRef = property.ref && property.ref.trim() !== ''\n const hasRefModelName = property.refModelName && property.refModelName.trim() !== ''\n const hasRefModelId = property.refModelId !== undefined && property.refModelId !== null\n if (!hasRef && !hasRefModelName && !hasRefModelId) {\n errors.push({\n field: 'ref',\n message: `List properties with refValueType 'Relation' require either a \"ref\", \"refModelName\", or \"refModelId\" field to be defined`,\n code: 'missing_ref',\n severity: 'error' as const,\n })\n }\n }\n }\n\n // Relation (single): ref is required\n if (property.dataType === ModelPropertyDataTypes.Relation) {\n const hasRef = property.ref && property.ref.trim() !== ''\n const hasRefModelName = property.refModelName && property.refModelName.trim() !== ''\n const hasRefModelId = property.refModelId !== undefined && property.refModelId !== null\n if (!hasRef && !hasRefModelName && !hasRefModelId) {\n errors.push({\n field: 'ref',\n message: `Property with dataType \"Relation\" requires either a \"ref\", \"refModelName\", or \"refModelId\" field to be defined`,\n code: 'missing_ref',\n severity: 'error' as const,\n })\n }\n if ((hasRef || hasRefModelName) && !hasRefModelId) {\n logger(`Property \"${property.name}\" has ref/refModelName but no refModelId - will be resolved asynchronously`)\n }\n }\n \n return {\n isValid: errors.length === 0,\n errors,\n }\n } catch (error) {\n logger('Error validating property structure:', error)\n return {\n isValid: false,\n errors: [{\n field: 'property',\n message: error instanceof Error ? error.message : 'Unknown validation error',\n code: 'validation_exception',\n severity: 'error' as const,\n }],\n }\n }\n }\n\n /**\n * Validate a property value against its validation rules\n */\n validatePropertyValue(\n value: any,\n dataType: ModelPropertyDataTypes,\n validationRules?: ValidationRules\n ): ValidationResult {\n const errors: ValidationError[] = []\n const warnings: ValidationError[] = []\n\n try {\n // Array values are only allowed for List properties\n if (dataType !== ModelPropertyDataTypes.List && Array.isArray(value)) {\n errors.push({\n field: 'value',\n message: 'Array values are only allowed for List properties. Use dataType \"List\" with refValueType to store multiple values.',\n code: 'array_not_allowed',\n severity: 'error' as const,\n })\n }\n\n // Build base TypeBox schema from dataType\n let schema: TSchema = this.getBaseSchemaForDataType(dataType)\n\n // Apply validation rules\n if (validationRules) {\n schema = this.applyValidationRules(schema, dataType, validationRules)\n }\n\n // Validate using TypeBox\n const isValid = Value.Check(schema, value)\n \n if (!isValid) {\n const typeBoxErrors = [...Value.Errors(schema, value)]\n errors.push(...typeBoxErrors.map(err => {\n const fieldPath = err.path || 'value'\n const enhancedMessage = this.enhanceErrorMessage(err, schema, fieldPath)\n \n return {\n field: fieldPath,\n message: enhancedMessage,\n code: String(err.type || 'value_validation_error'),\n severity: 'error' as const,\n }\n }))\n }\n\n // Additional custom validations\n if (validationRules) {\n const customErrors = this.validateCustomRules(value, validationRules)\n errors.push(...customErrors)\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n logger('Error validating property value:', error)\n return {\n isValid: false,\n errors: [{\n field: 'value',\n message: error instanceof Error ? error.message : 'Unknown validation error',\n code: 'validation_exception',\n severity: 'error' as const,\n }],\n }\n }\n }\n\n /**\n * Validate a specific property within a schema\n */\n validateProperty(\n schema: SchemaMachineContext,\n modelName: string,\n propertyName: string,\n propertyData?: ModelPropertyMachineContext\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n // Check if model exists\n if (!schema.models || !schema.models[modelName]) {\n errors.push({\n field: 'model',\n message: `Model \"${modelName}\" not found in schema`,\n code: 'model_not_found',\n severity: 'error' as const,\n })\n return { isValid: false, errors }\n }\n\n const model = schema.models[modelName]\n\n // Check if property exists in model\n // If the property name has changed (renamed), check if the original name exists\n let propertyDefinition = model.properties?.[propertyName]\n let actualPropertyName = propertyName\n \n if (!propertyDefinition && propertyData?._originalValues?.name) {\n const originalName = propertyData._originalValues.name\n // If the current name differs from the original, check if original exists\n if (originalName !== propertyName && model.properties?.[originalName]) {\n propertyDefinition = model.properties[originalName]\n actualPropertyName = originalName\n // Property is being renamed, which is allowed - continue validation\n }\n }\n \n if (!propertyDefinition) {\n errors.push({\n field: 'property',\n message: `Property \"${propertyName}\" not found in model \"${modelName}\"`,\n code: 'property_not_found',\n severity: 'error' as const,\n })\n return { isValid: false, errors }\n }\n\n // If propertyData is provided, validate its structure\n if (propertyData) {\n const structureResult = this.validatePropertyStructure(propertyData)\n errors.push(...structureResult.errors)\n }\n\n // Validate property definition structure\n if (!propertyDefinition.type) {\n errors.push({\n field: 'property.type',\n message: 'Property type is required',\n code: 'missing_type',\n severity: 'error' as const,\n })\n }\n\n // Validate Relation: requires model\n if (propertyDefinition.type === 'Relation') {\n if (!propertyDefinition.model || propertyDefinition.model.trim() === '') {\n errors.push({\n field: 'property.model',\n message: `Property with type \"Relation\" requires a \"model\" field to be defined`,\n code: 'missing_ref',\n severity: 'error' as const,\n })\n } else if (!schema.models[propertyDefinition.model]) {\n errors.push({\n field: 'property.model',\n message: `Referenced model \"${propertyDefinition.model}\" not found in schema`,\n code: 'invalid_reference',\n severity: 'error' as const,\n })\n }\n }\n\n // Validate List: requires items with type; model required only when items.type === 'Relation'\n if (propertyDefinition.type === 'List') {\n const items = (propertyDefinition as any).items\n if (!items || !items.type) {\n errors.push({\n field: 'property.items',\n message: 'List properties require \"items\" with \"type\" (e.g. items: { type: \"Text\" } or items: { type: \"Relation\", model: \"Tag\" })',\n code: 'missing_items',\n severity: 'error' as const,\n })\n } else if (items.type === 'Relation' || items.type === 'RelationProperty') {\n const model = items.model || propertyDefinition.model\n if (!model || String(model).trim() === '') {\n errors.push({\n field: 'property.items.model',\n message: 'List of relations requires \"items.model\" to specify the related model',\n code: 'missing_ref',\n severity: 'error' as const,\n })\n } else if (schema.models && !schema.models[model]) {\n errors.push({\n field: 'property.items.model',\n message: `Referenced model \"${model}\" not found in schema`,\n code: 'invalid_reference',\n severity: 'error' as const,\n })\n }\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Validate model structure (basic structure checks)\n */\n validateModelStructure(\n model: ModelMachineContext & { properties?: { [key: string]: any } }\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n // Validate model name\n if (!model.modelName || model.modelName.trim() === '') {\n errors.push({\n field: 'modelName',\n message: 'Model name is required',\n code: 'missing_model_name',\n severity: 'error' as const,\n })\n }\n\n // Validate schema name\n if (!model.schemaName || model.schemaName.trim() === '') {\n errors.push({\n field: 'schemaName',\n message: 'Schema name is required',\n code: 'missing_schema_name',\n severity: 'error' as const,\n })\n }\n\n // Validate properties is an object\n if (model.properties && typeof model.properties !== 'object') {\n errors.push({\n field: 'properties',\n message: 'Properties must be an object',\n code: 'invalid_properties',\n severity: 'error' as const,\n })\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Validate a model against a schema WITHOUT requiring it to be in the schema's context\n * This allows validation before registration, preventing update loops\n */\n validateModelAgainstSchema(\n schema: SchemaMachineContext,\n modelName: string,\n modelData: ModelMachineContext & { properties?: { [key: string]: any } }\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n // Create a temporary schema context that includes this model for validation purposes\n // This allows validateProperty to work without actually adding the model to the real schema\n const tempSchemaContext: SchemaMachineContext = {\n ...schema,\n models: {\n ...schema.models,\n [modelName]: {\n properties: modelData.properties || {},\n },\n },\n }\n\n // Use validateModel which now works because the model is in the temp context\n return this.validateModel(tempSchemaContext, modelName, modelData)\n }\n\n /**\n * Validate a model within a schema (requires model to already be in schema context)\n */\n validateModel(\n schema: SchemaMachineContext,\n modelName: string,\n modelData?: ModelMachineContext\n ): ValidationResult {\n const errors: ValidationError[] = []\n\n if (!schema.models || !schema.models[modelName]) {\n errors.push({\n field: 'model',\n message: `Model \"${modelName}\" not found in schema`,\n code: 'model_not_found',\n severity: 'error' as const,\n })\n return { isValid: false, errors }\n }\n\n const model = schema.models[modelName]\n\n // Validate all properties in the model\n if (model.properties) {\n for (const [propertyName, propertyDef] of Object.entries(model.properties)) {\n const propertyResult = this.validateProperty(schema, modelName, propertyName)\n if (!propertyResult.isValid) {\n errors.push(...propertyResult.errors.map(err => ({\n ...err,\n field: `${modelName}.${propertyName}.${err.field}`,\n })))\n }\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Validate entire schema\n */\n validateSchema(schema: SchemaMachineContext): ValidationResult {\n const errors: ValidationError[] = []\n\n // Validate schema name\n if (!schema.schemaName || schema.schemaName.trim() === '') {\n errors.push({\n field: 'schemaName',\n message: 'Schema name is required',\n code: 'missing_schema_name',\n severity: 'error' as const,\n })\n }\n\n // Validate metadata\n if (!schema.metadata) {\n errors.push({\n field: 'metadata',\n message: 'Schema metadata is required',\n code: 'missing_metadata',\n severity: 'error' as const,\n })\n } else {\n if (!schema.metadata.name || schema.metadata.name.trim() === '') {\n errors.push({\n field: 'metadata.name',\n message: 'Schema metadata name is required',\n code: 'missing_metadata_name',\n severity: 'error' as const,\n })\n }\n }\n\n // Validate models if they exist\n if (schema.models && Object.keys(schema.models).length > 0) {\n // Validate each model\n for (const modelName of Object.keys(schema.models)) {\n const modelResult = this.validateModel(schema, modelName)\n if (!modelResult.isValid) {\n errors.push(...modelResult.errors)\n }\n }\n }\n\n return {\n isValid: errors.length === 0,\n errors,\n }\n }\n\n /**\n * Get base TypeBox schema for a data type\n */\n private getBaseSchemaForDataType(dataType: ModelPropertyDataTypes): TSchema {\n switch (dataType) {\n case ModelPropertyDataTypes.Text:\n case ModelPropertyDataTypes.Html:\n return Type.String()\n case ModelPropertyDataTypes.Number:\n return Type.Number()\n case ModelPropertyDataTypes.Boolean:\n return Type.Boolean()\n case ModelPropertyDataTypes.Date:\n return Type.String({ format: 'date-time' })\n case ModelPropertyDataTypes.Json:\n return Type.Any()\n case ModelPropertyDataTypes.List:\n return Type.Array(Type.Any())\n case ModelPropertyDataTypes.Relation:\n case ModelPropertyDataTypes.Image:\n case ModelPropertyDataTypes.File:\n return Type.Union([Type.String(), Type.Null()])\n default:\n return Type.Any()\n }\n }\n\n /**\n * Apply validation rules to a TypeBox schema\n */\n private applyValidationRules(\n schema: TSchema,\n dataType: ModelPropertyDataTypes,\n rules: ValidationRules\n ): TSchema {\n let result = schema\n\n // Apply pattern (regex) for strings\n if (rules.pattern && (dataType === ModelPropertyDataTypes.Text || dataType === ModelPropertyDataTypes.Html)) {\n try {\n const regex = new RegExp(rules.pattern)\n result = Type.RegExp(regex)\n } catch (error) {\n logger('Invalid regex pattern:', rules.pattern, error)\n }\n }\n\n // Apply minLength/maxLength for strings\n if (dataType === ModelPropertyDataTypes.Text || dataType === ModelPropertyDataTypes.Html) {\n const stringSchema = Type.String()\n if (rules.minLength !== undefined) {\n result = Type.String({ minLength: rules.minLength })\n }\n if (rules.maxLength !== undefined) {\n if (rules.minLength !== undefined) {\n result = Type.String({ minLength: rules.minLength, maxLength: rules.maxLength })\n } else {\n result = Type.String({ maxLength: rules.maxLength })\n }\n }\n }\n\n // Apply enum\n if (rules.enum && Array.isArray(rules.enum) && rules.enum.length > 0) {\n result = Type.Union(rules.enum.map(val => Type.Literal(val)))\n }\n\n return result\n }\n\n /**\n * Validate custom validation rules\n */\n private validateCustomRules(\n value: any,\n rules: ValidationRules\n ): ValidationError[] {\n const errors: ValidationError[] = []\n\n // Custom validator reference (would need to be implemented based on your needs)\n if (rules.custom) {\n // TODO: Implement custom validator lookup and execution\n logger('Custom validator not yet implemented:', rules.custom)\n }\n\n return errors\n }\n}\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAUA,MAAM,MAAM,GAAG,KAAK,CAAC,2BAA2B,CAAC;AAEjD;;AAEG;MACU,uBAAuB,CAAA;AAClC;;AAEG;AACK,IAAA,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;AACjC,gBAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;YACtD;AACA,YAAA,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE;AACjC,gBAAA,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE;AACjC,oBAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;gBAClF;qBAAO;AACL,oBAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;gBACtD;YACF;QACF;;QAGA,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACpE,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/D;AAEA,QAAA,OAAO,MAAM;IACf;AAEA;;AAEG;IACK,mBAAmB,CACzB,KAAU,EACV,KAAsB,EAAA;QAEtB,MAAM,MAAM,GAAsB,EAAE;;AAGpC,QAAA,IAAI,KAAK,CAAC,MAAM,EAAE;;AAEhB,YAAA,MAAM,CAAC,uCAAuC,EAAE,KAAK,CAAC,MAAM,CAAC;QAC/D;AAEA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var xstate = require('xstate');
|
|
4
4
|
require('reflect-metadata');
|
|
5
|
-
var main_cjs = require('./index-
|
|
5
|
+
var main_cjs = require('./index-CA4i5TA7.js');
|
|
6
6
|
require('pluralize');
|
|
7
7
|
var drizzleOrm = require('drizzle-orm');
|
|
8
8
|
var debug = require('debug');
|
|
9
|
-
var Schema = require('./Schema-
|
|
9
|
+
var Schema = require('./Schema-B6ifYEhD.js');
|
|
10
10
|
require('immer');
|
|
11
11
|
require('drizzle-orm/sqlite-core');
|
|
12
12
|
require('nanoid');
|
|
@@ -31,7 +31,7 @@ require('rimraf');
|
|
|
31
31
|
require('child_process');
|
|
32
32
|
require('url');
|
|
33
33
|
require('graphql-request');
|
|
34
|
-
require('./SchemaValidationService-
|
|
34
|
+
require('./SchemaValidationService-OFyzZIUX.js');
|
|
35
35
|
require('@sinclair/typebox/value');
|
|
36
36
|
|
|
37
37
|
const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
@@ -42,12 +42,12 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
|
42
42
|
*/
|
|
43
43
|
async function getSchemaNameFromModel(modelName) {
|
|
44
44
|
// Get the latest schema files and find which one contains this model
|
|
45
|
-
const schemaHelpersMod = await Promise.resolve().then(function () { return require('./index-
|
|
45
|
+
const schemaHelpersMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.schema$1; });
|
|
46
46
|
const { listLatestSchemaFiles } = schemaHelpersMod;
|
|
47
47
|
const latestSchemas = await listLatestSchemaFiles();
|
|
48
48
|
for (const schema of latestSchemas) {
|
|
49
49
|
try {
|
|
50
|
-
const fileManagerMod = await Promise.resolve().then(function () { return require('./index-
|
|
50
|
+
const fileManagerMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.BaseFileManager$1; });
|
|
51
51
|
const { BaseFileManager } = fileManagerMod;
|
|
52
52
|
const content = await BaseFileManager.readFileAsString(schema.filePath);
|
|
53
53
|
const schemaFile = JSON.parse(content);
|
|
@@ -65,7 +65,7 @@ async function getSchemaNameFromModel(modelName) {
|
|
|
65
65
|
const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
66
66
|
const _saveToSchema = async () => {
|
|
67
67
|
// Use dynamic import to break circular dependency
|
|
68
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
68
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-OFyzZIUX.js'); });
|
|
69
69
|
const { SchemaValidationService } = validationServiceMod;
|
|
70
70
|
const validationService = new SchemaValidationService();
|
|
71
71
|
// Validate property structure before saving
|
|
@@ -84,13 +84,13 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
84
84
|
throw new Error(`Model not found for modelId: ${context.modelId}`);
|
|
85
85
|
}
|
|
86
86
|
// Persist to database only - schema file is updated only when user calls Schema.saveNewVersion()
|
|
87
|
-
const dbMod = await Promise.resolve().then(function () { return require('./index-
|
|
87
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.db; });
|
|
88
88
|
const { savePropertyToDb } = dbMod;
|
|
89
89
|
await savePropertyToDb(context);
|
|
90
90
|
// Mark schema as draft so user knows to save
|
|
91
91
|
const schemaName = context._schemaName ?? (await getSchemaNameFromModel(context.modelName));
|
|
92
92
|
if (schemaName) {
|
|
93
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
93
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-B6ifYEhD.js'); });
|
|
94
94
|
const { Schema } = schemaMod;
|
|
95
95
|
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
96
96
|
schema.getService().send({
|
|
@@ -123,7 +123,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
123
123
|
const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
124
124
|
if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
125
125
|
try {
|
|
126
|
-
const dbMod = await Promise.resolve().then(function () { return require('./index-
|
|
126
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.db; });
|
|
127
127
|
const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
|
|
128
128
|
let fromDb;
|
|
129
129
|
for (let attempt = 0; attempt < 6; attempt++) {
|
|
@@ -162,13 +162,16 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
162
162
|
if (!fullContext._originalValues) {
|
|
163
163
|
logger$2('No original values to compare against');
|
|
164
164
|
logger$2(`[compareAndMarkDraft] Context: modelName=${fullContext.modelName}, name=${fullContext.name}, id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}`);
|
|
165
|
+
// #region agent log
|
|
166
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'compareAndMarkDraft.ts:noOriginalValues', message: 'compareAndMarkDraft early path - no _originalValues', data: { name: fullContext.name, modelName: fullContext.modelName, schemaFileId: schemaFileId, willSave: !!(fullContext.modelName && fullContext.name && schemaFileId) }, timestamp: Date.now(), hypothesisId: 'A' }) }).catch(() => { });
|
|
167
|
+
// #endregion
|
|
165
168
|
// If we have a name and modelName, try to save to database anyway
|
|
166
169
|
// This ensures name changes are persisted even if _originalValues isn't initialized yet
|
|
167
170
|
// We need either schemaFileId (id or _propertyFileId) to find the property in the database
|
|
168
171
|
if (fullContext.modelName && fullContext.name && schemaFileId) {
|
|
169
172
|
logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
|
|
170
173
|
try {
|
|
171
|
-
const dbMod = await Promise.resolve().then(function () { return require('./index-
|
|
174
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.db; });
|
|
172
175
|
const { savePropertyToDb } = dbMod;
|
|
173
176
|
// Ensure _propertyFileId is set for savePropertyToDb to find the property
|
|
174
177
|
const contextWithFileId = {
|
|
@@ -190,6 +193,9 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
190
193
|
return;
|
|
191
194
|
}
|
|
192
195
|
logger$2(`[compareAndMarkDraft] Comparing: context.name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
196
|
+
// #region agent log
|
|
197
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'compareAndMarkDraft.ts:beforeHasChanges', message: 'compareAndMarkDraft before hasChanges', data: { name: fullContext.name, originalName: fullContext._originalValues?.name, id: fullContext.id, schemaFileId: fullContext._propertyFileId || fullContext.id }, timestamp: Date.now(), hypothesisId: 'A' }) }).catch(() => { });
|
|
198
|
+
// #endregion
|
|
193
199
|
// Compare current values with original
|
|
194
200
|
// Only compare property fields, not internal fields
|
|
195
201
|
const propertyFields = ['name', 'dataType', 'ref', 'refModelName', 'refModelId', 'refValueType', 'storageType', 'localStorageDir', 'filenameSuffix', 'modelName', 'modelId'];
|
|
@@ -227,22 +233,33 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
227
233
|
if (hasChanges) {
|
|
228
234
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
|
|
229
235
|
logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
236
|
+
// #region agent log
|
|
237
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'compareAndMarkDraft.ts:hasChanges-callingSave', message: 'compareAndMarkDraft calling savePropertyToDb', data: { name: fullContext.name, originalName: fullContext._originalValues?.name, schemaFileId: fullContext._propertyFileId || fullContext.id }, timestamp: Date.now(), hypothesisId: 'A' }) }).catch(() => { });
|
|
238
|
+
// #endregion
|
|
230
239
|
// Use dynamic import to break circular dependency
|
|
231
|
-
const dbMod = await Promise.resolve().then(function () { return require('./index-
|
|
240
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.db; });
|
|
232
241
|
const { savePropertyToDb } = dbMod;
|
|
233
242
|
// Save to database (but not JSON file) - always save to DB when there are changes
|
|
234
243
|
try {
|
|
235
244
|
await savePropertyToDb(fullContext);
|
|
236
245
|
logger$2(`[compareAndMarkDraft] Successfully saved property ${fullContext.modelName}:${fullContext.name} to database`);
|
|
246
|
+
// #region agent log
|
|
247
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'compareAndMarkDraft.ts:savePropertyToDbSuccess', message: 'savePropertyToDb completed successfully', data: { name: fullContext.name }, timestamp: Date.now(), hypothesisId: 'A' }) }).catch(() => { });
|
|
248
|
+
// #endregion
|
|
237
249
|
}
|
|
238
250
|
catch (error) {
|
|
239
251
|
logger$2(`[compareAndMarkDraft] Error saving property to database: ${error}`);
|
|
252
|
+
// #region agent log
|
|
253
|
+
if (typeof fetch === 'function') {
|
|
254
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'compareAndMarkDraft.ts:savePropertyToDbError', message: 'savePropertyToDb FAILED', data: { name: fullContext.name, error: String(error) }, timestamp: Date.now(), hypothesisId: 'B' }) }).catch(() => { });
|
|
255
|
+
}
|
|
256
|
+
// #endregion
|
|
240
257
|
throw error;
|
|
241
258
|
}
|
|
242
259
|
// Mark schema as draft if schema name is available
|
|
243
260
|
if (fullContext._schemaName) {
|
|
244
261
|
// Get the Schema instance and mark it as draft
|
|
245
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
262
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-B6ifYEhD.js'); });
|
|
246
263
|
const { Schema } = schemaMod;
|
|
247
264
|
const schema = Schema.create(fullContext._schemaName, {
|
|
248
265
|
waitForReady: false,
|
|
@@ -259,7 +276,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
259
276
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
|
|
260
277
|
// Clear isEdited flag in database
|
|
261
278
|
try {
|
|
262
|
-
const seedSchemaMod = await Promise.resolve().then(function () { return require('./index-
|
|
279
|
+
const seedSchemaMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.schema; });
|
|
263
280
|
const { properties: propertiesTable, models: modelsTable } = seedSchemaMod;
|
|
264
281
|
const drizzleMod = await import('drizzle-orm');
|
|
265
282
|
const { eq, and } = drizzleMod;
|
|
@@ -323,7 +340,7 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
323
340
|
// Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
|
|
324
341
|
await new Promise((r) => setTimeout(r, 60));
|
|
325
342
|
try {
|
|
326
|
-
const dbMod = await Promise.resolve().then(function () { return require('./index-
|
|
343
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CA4i5TA7.js'); }).then(function (n) { return n.db; });
|
|
327
344
|
const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
|
|
328
345
|
// Try pending write first (property row may not exist yet)
|
|
329
346
|
if (fullContext.modelName === undefined && schemaFileId) {
|
|
@@ -375,14 +392,19 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
375
392
|
fullContext = { ...fullContext, dataType: (fullContext.dataType ?? context._originalValues?.dataType) || 'Text' };
|
|
376
393
|
}
|
|
377
394
|
// Use dynamic imports to break circular dependencies
|
|
378
|
-
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
395
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-OFyzZIUX.js'); });
|
|
379
396
|
const { SchemaValidationService } = validationServiceMod;
|
|
380
397
|
const validationService = new SchemaValidationService();
|
|
381
|
-
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-
|
|
398
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-B6ifYEhD.js'); });
|
|
382
399
|
const { Schema } = schemaMod;
|
|
383
400
|
// Validate property structure
|
|
384
401
|
const structureResult = validationService.validatePropertyStructure(fullContext);
|
|
385
402
|
if (!structureResult.isValid) {
|
|
403
|
+
// #region agent log
|
|
404
|
+
if (typeof fetch === 'function') {
|
|
405
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'validateProperty.ts:structureInvalid', message: 'validateProperty structure validation FAILED', data: { name: fullContext.name, errors: structureResult.errors?.map((e) => e.message || e.code) }, timestamp: Date.now(), hypothesisId: 'D' }) }).catch(() => { });
|
|
406
|
+
}
|
|
407
|
+
// #endregion
|
|
386
408
|
sendBack({ type: 'validationError', errors: structureResult.errors });
|
|
387
409
|
return;
|
|
388
410
|
}
|
|
@@ -422,6 +444,11 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
422
444
|
return true; // Critical error
|
|
423
445
|
});
|
|
424
446
|
if (criticalErrors.length > 0) {
|
|
447
|
+
// #region agent log
|
|
448
|
+
if (typeof fetch === 'function') {
|
|
449
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'validateProperty.ts:schemaCriticalErrors', message: 'validateProperty schema validation FAILED (critical)', data: { name: fullContext.name, isRenamed: !!(fullContext._originalValues?.name && fullContext._originalValues.name !== fullContext.name), criticalErrors: criticalErrors?.map((e) => e.message || e.code) }, timestamp: Date.now(), hypothesisId: 'D' }) }).catch(() => { });
|
|
450
|
+
}
|
|
451
|
+
// #endregion
|
|
425
452
|
sendBack({ type: 'validationError', errors: criticalErrors });
|
|
426
453
|
return;
|
|
427
454
|
}
|
|
@@ -506,6 +533,11 @@ const modelPropertyMachine = xstate.setup({
|
|
|
506
533
|
updateContext: {
|
|
507
534
|
actions: xstate.assign(({ context, event }) => {
|
|
508
535
|
const newContext = Object.assign({}, context);
|
|
536
|
+
// #region agent log
|
|
537
|
+
if (event.name !== undefined && event.name !== context.name) {
|
|
538
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'modelPropertyMachine.ts:updateContext', message: 'Name change via updateContext', data: { oldName: context.name, newName: event.name, id: context.id, _propertyFileId: context._propertyFileId, hasOriginalValues: !!context._originalValues }, timestamp: Date.now(), hypothesisId: 'A' }) }).catch(() => { });
|
|
539
|
+
}
|
|
540
|
+
// #endregion
|
|
509
541
|
// Check if this is only updating internal fields
|
|
510
542
|
const onlyInternalFields = Object.keys(event).every((key) => {
|
|
511
543
|
return key === 'type' || key.startsWith('_');
|
|
@@ -1132,6 +1164,41 @@ class ModelProperty {
|
|
|
1132
1164
|
// If we can't get schema name, that's okay - it will be set later if needed
|
|
1133
1165
|
}
|
|
1134
1166
|
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Resolve schema name from DB when _schemaName is missing (e.g. destroy ran before _setSchemaName finished).
|
|
1169
|
+
* Uses context.id (schemaFileId) and context.modelId to query properties → model_schemas → schemas.
|
|
1170
|
+
*/
|
|
1171
|
+
async _resolveSchemaNameForDestroy(db, context) {
|
|
1172
|
+
try {
|
|
1173
|
+
let modelId = context.modelId;
|
|
1174
|
+
const schemaFileId = context.id ?? context._propertyFileId;
|
|
1175
|
+
// If we don't have modelId, get it from the property row by schemaFileId
|
|
1176
|
+
if (modelId == null && schemaFileId) {
|
|
1177
|
+
const propRows = await db
|
|
1178
|
+
.select({ modelId: main_cjs.properties.modelId })
|
|
1179
|
+
.from(main_cjs.properties)
|
|
1180
|
+
.where(drizzleOrm.eq(main_cjs.properties.schemaFileId, schemaFileId))
|
|
1181
|
+
.limit(1);
|
|
1182
|
+
if (propRows.length > 0 && propRows[0].modelId != null) {
|
|
1183
|
+
modelId = propRows[0].modelId;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
if (modelId == null)
|
|
1187
|
+
return undefined;
|
|
1188
|
+
// Resolve modelFileId (string) to database ID (number) if needed - modelSchemas.modelId expects number
|
|
1189
|
+
const modelIdNum = typeof modelId === 'string' ? await main_cjs.getModelIdByFileId(modelId) : modelId;
|
|
1190
|
+
const modelSchemaRecords = await db
|
|
1191
|
+
.select({ schemaName: main_cjs.schemas.name })
|
|
1192
|
+
.from(main_cjs.modelSchemas)
|
|
1193
|
+
.innerJoin(main_cjs.schemas, drizzleOrm.eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
|
|
1194
|
+
.where(drizzleOrm.eq(main_cjs.modelSchemas.modelId, modelIdNum))
|
|
1195
|
+
.limit(1);
|
|
1196
|
+
return modelSchemaRecords.length > 0 ? modelSchemaRecords[0].schemaName ?? undefined : undefined;
|
|
1197
|
+
}
|
|
1198
|
+
catch {
|
|
1199
|
+
return undefined;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1135
1202
|
/**
|
|
1136
1203
|
* Manually set the schema name for this property
|
|
1137
1204
|
* Useful when you know the schema name from context (e.g., when working with Schema instances)
|
|
@@ -1419,6 +1486,11 @@ class ModelProperty {
|
|
|
1419
1486
|
const modelName = modelRecords[0].name;
|
|
1420
1487
|
// Build property data
|
|
1421
1488
|
// id is now the schemaFileId (string), _dbId is the database integer ID
|
|
1489
|
+
// #region agent log
|
|
1490
|
+
if (typeof fetch === 'function') {
|
|
1491
|
+
fetch('http://127.0.0.1:7242/ingest/0978b378-ebae-46bf-8fd3-134ef2e16cdd', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Debug-Session-Id': '9ee076' }, body: JSON.stringify({ sessionId: '9ee076', location: 'ModelProperty.ts:createById', message: 'createById loading from DB', data: { propertyFileId, name: propertyRecord.name, modelName }, timestamp: Date.now(), hypothesisId: 'E' }) }).catch(() => { });
|
|
1492
|
+
}
|
|
1493
|
+
// #endregion
|
|
1422
1494
|
const propertyData = {
|
|
1423
1495
|
id: propertyFileId, // schemaFileId (string) - public ID
|
|
1424
1496
|
_dbId: propertyRecord.id ?? undefined, // Database integer ID - internal only
|
|
@@ -1675,11 +1747,15 @@ class ModelProperty {
|
|
|
1675
1747
|
getService: (instance) => instance._service,
|
|
1676
1748
|
doDestroy: async () => {
|
|
1677
1749
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1678
|
-
|
|
1750
|
+
let schemaName = context._schemaName;
|
|
1679
1751
|
const modelName = context.modelName;
|
|
1680
1752
|
const propertyName = context.name;
|
|
1681
1753
|
if (!modelName || !propertyName)
|
|
1682
1754
|
return;
|
|
1755
|
+
// Resolve schema name from DB when _schemaName is missing (e.g. destroy ran before _setSchemaName finished)
|
|
1756
|
+
if (!schemaName && db) {
|
|
1757
|
+
schemaName = await this._resolveSchemaNameForDestroy(db, context);
|
|
1758
|
+
}
|
|
1683
1759
|
if (db && schemaName) {
|
|
1684
1760
|
const propertyRecords = await db
|
|
1685
1761
|
.select({ propertyId: main_cjs.properties.id })
|
|
@@ -1722,4 +1798,4 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
1722
1798
|
});
|
|
1723
1799
|
|
|
1724
1800
|
exports.ModelProperty = ModelProperty;
|
|
1725
|
-
//# sourceMappingURL=ModelProperty-
|
|
1801
|
+
//# sourceMappingURL=ModelProperty-DcAM5M8T.js.map
|