@514labs/moose-lib 0.6.446 → 0.6.447

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.
@@ -1012,6 +1012,50 @@ var generateAssertFunction = (ctx, type, typeName) => {
1012
1012
  config: { equals: false, guard: false }
1013
1013
  });
1014
1014
  };
1015
+ var getPropertyName = (prop) => prop.key.constants?.[0]?.values?.[0]?.value;
1016
+ var patchMetadataForInsert = (metadata, computedColumns, defaultColumns) => {
1017
+ for (const obj of metadata.objects) {
1018
+ const keep = [];
1019
+ for (const prop of obj.type.properties) {
1020
+ const name = getPropertyName(prop);
1021
+ if (name !== void 0 && computedColumns.has(name)) continue;
1022
+ if (name !== void 0 && defaultColumns.has(name)) {
1023
+ prop.value.optional = true;
1024
+ prop.value.required = false;
1025
+ }
1026
+ keep.push(prop);
1027
+ }
1028
+ obj.type.properties.length = 0;
1029
+ obj.type.properties.push(...keep);
1030
+ }
1031
+ };
1032
+ var withInsertableMetadata = (columns, fn) => {
1033
+ const original = import_MetadataFactory.MetadataFactory.analyze;
1034
+ import_MetadataFactory.MetadataFactory.analyze = (props) => {
1035
+ const result = original(props);
1036
+ if (result.success) {
1037
+ patchMetadataForInsert(result.data, columns.computed, columns.defaults);
1038
+ }
1039
+ return result;
1040
+ };
1041
+ try {
1042
+ return fn();
1043
+ } finally {
1044
+ import_MetadataFactory.MetadataFactory.analyze = original;
1045
+ }
1046
+ };
1047
+ var generateInsertValidateFunction = (ctx, type, columns, typeName) => withInsertableMetadata(
1048
+ columns,
1049
+ () => generateValidateFunction(ctx, type, typeName)
1050
+ );
1051
+ var generateInsertIsFunction = (ctx, type, columns, typeName) => withInsertableMetadata(
1052
+ columns,
1053
+ () => generateIsFunction(ctx, type, typeName)
1054
+ );
1055
+ var generateInsertAssertFunction = (ctx, type, columns, typeName) => withInsertableMetadata(
1056
+ columns,
1057
+ () => generateAssertFunction(ctx, type, typeName)
1058
+ );
1015
1059
  var generateHttpAssertQueryFunction = (ctx, type, typeName) => {
1016
1060
  const typiaCtx = toTypiaContext(ctx);
1017
1061
  return import_HttpAssertQueryProgrammer.HttpAssertQueryProgrammer.write({
@@ -1215,18 +1259,16 @@ var transformNewMooseResource = (node, checker, ctx) => {
1215
1259
  }
1216
1260
  const typiaCtx = ctx.typiaContext;
1217
1261
  let internalArguments;
1262
+ let columns;
1218
1263
  if (typeName === "DeadLetterQueue") {
1219
1264
  internalArguments = [generateAssertFunction(typiaCtx, typeAtLocation)];
1220
1265
  } else {
1266
+ columns = toColumns(typeAtLocation, checker, {
1267
+ allowIndexSignatures
1268
+ });
1221
1269
  internalArguments = [
1222
1270
  generateJsonSchemas(typiaCtx, typeAtLocation),
1223
- parseAsAny(
1224
- JSON.stringify(
1225
- toColumns(typeAtLocation, checker, {
1226
- allowIndexSignatures
1227
- })
1228
- )
1229
- )
1271
+ parseAsAny(JSON.stringify(columns))
1230
1272
  ];
1231
1273
  }
1232
1274
  const resourceName = checker.getSymbolAtLocation(node.expression).name;
@@ -1258,6 +1300,48 @@ var transformNewMooseResource = (node, checker, ctx) => {
1258
1300
  true
1259
1301
  );
1260
1302
  updatedArgs = [...updatedArgs, validatorsObject];
1303
+ if (resourceName === "OlapTable" && columns) {
1304
+ const insertColumnSets = {
1305
+ computed: new Set(
1306
+ columns.filter((c) => c.alias != null || c.materialized != null).map((c) => c.name)
1307
+ ),
1308
+ defaults: new Set(
1309
+ columns.filter((c) => c.default != null).map((c) => c.name)
1310
+ )
1311
+ };
1312
+ const insertValidatorsObject = import_typescript5.factory.createObjectLiteralExpression(
1313
+ [
1314
+ import_typescript5.factory.createPropertyAssignment(
1315
+ import_typescript5.factory.createIdentifier("validate"),
1316
+ wrapValidateFunction(
1317
+ generateInsertValidateFunction(
1318
+ typiaCtx,
1319
+ typeAtLocation,
1320
+ insertColumnSets
1321
+ )
1322
+ )
1323
+ ),
1324
+ import_typescript5.factory.createPropertyAssignment(
1325
+ import_typescript5.factory.createIdentifier("assert"),
1326
+ generateInsertAssertFunction(
1327
+ typiaCtx,
1328
+ typeAtLocation,
1329
+ insertColumnSets
1330
+ )
1331
+ ),
1332
+ import_typescript5.factory.createPropertyAssignment(
1333
+ import_typescript5.factory.createIdentifier("is"),
1334
+ generateInsertIsFunction(
1335
+ typiaCtx,
1336
+ typeAtLocation,
1337
+ insertColumnSets
1338
+ )
1339
+ )
1340
+ ],
1341
+ true
1342
+ );
1343
+ updatedArgs = [...updatedArgs, insertValidatorsObject];
1344
+ }
1261
1345
  if (resourceName === "IngestPipeline") {
1262
1346
  updatedArgs = [
1263
1347
  ...updatedArgs,