@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.
@@ -984,6 +984,50 @@ var generateAssertFunction = (ctx, type, typeName) => {
984
984
  config: { equals: false, guard: false }
985
985
  });
986
986
  };
987
+ var getPropertyName = (prop) => prop.key.constants?.[0]?.values?.[0]?.value;
988
+ var patchMetadataForInsert = (metadata, computedColumns, defaultColumns) => {
989
+ for (const obj of metadata.objects) {
990
+ const keep = [];
991
+ for (const prop of obj.type.properties) {
992
+ const name = getPropertyName(prop);
993
+ if (name !== void 0 && computedColumns.has(name)) continue;
994
+ if (name !== void 0 && defaultColumns.has(name)) {
995
+ prop.value.optional = true;
996
+ prop.value.required = false;
997
+ }
998
+ keep.push(prop);
999
+ }
1000
+ obj.type.properties.length = 0;
1001
+ obj.type.properties.push(...keep);
1002
+ }
1003
+ };
1004
+ var withInsertableMetadata = (columns, fn) => {
1005
+ const original = MetadataFactory.analyze;
1006
+ MetadataFactory.analyze = (props) => {
1007
+ const result = original(props);
1008
+ if (result.success) {
1009
+ patchMetadataForInsert(result.data, columns.computed, columns.defaults);
1010
+ }
1011
+ return result;
1012
+ };
1013
+ try {
1014
+ return fn();
1015
+ } finally {
1016
+ MetadataFactory.analyze = original;
1017
+ }
1018
+ };
1019
+ var generateInsertValidateFunction = (ctx, type, columns, typeName) => withInsertableMetadata(
1020
+ columns,
1021
+ () => generateValidateFunction(ctx, type, typeName)
1022
+ );
1023
+ var generateInsertIsFunction = (ctx, type, columns, typeName) => withInsertableMetadata(
1024
+ columns,
1025
+ () => generateIsFunction(ctx, type, typeName)
1026
+ );
1027
+ var generateInsertAssertFunction = (ctx, type, columns, typeName) => withInsertableMetadata(
1028
+ columns,
1029
+ () => generateAssertFunction(ctx, type, typeName)
1030
+ );
987
1031
  var generateHttpAssertQueryFunction = (ctx, type, typeName) => {
988
1032
  const typiaCtx = toTypiaContext(ctx);
989
1033
  return HttpAssertQueryProgrammer.write({
@@ -1187,18 +1231,16 @@ var transformNewMooseResource = (node, checker, ctx) => {
1187
1231
  }
1188
1232
  const typiaCtx = ctx.typiaContext;
1189
1233
  let internalArguments;
1234
+ let columns;
1190
1235
  if (typeName === "DeadLetterQueue") {
1191
1236
  internalArguments = [generateAssertFunction(typiaCtx, typeAtLocation)];
1192
1237
  } else {
1238
+ columns = toColumns(typeAtLocation, checker, {
1239
+ allowIndexSignatures
1240
+ });
1193
1241
  internalArguments = [
1194
1242
  generateJsonSchemas(typiaCtx, typeAtLocation),
1195
- parseAsAny(
1196
- JSON.stringify(
1197
- toColumns(typeAtLocation, checker, {
1198
- allowIndexSignatures
1199
- })
1200
- )
1201
- )
1243
+ parseAsAny(JSON.stringify(columns))
1202
1244
  ];
1203
1245
  }
1204
1246
  const resourceName = checker.getSymbolAtLocation(node.expression).name;
@@ -1230,6 +1272,48 @@ var transformNewMooseResource = (node, checker, ctx) => {
1230
1272
  true
1231
1273
  );
1232
1274
  updatedArgs = [...updatedArgs, validatorsObject];
1275
+ if (resourceName === "OlapTable" && columns) {
1276
+ const insertColumnSets = {
1277
+ computed: new Set(
1278
+ columns.filter((c) => c.alias != null || c.materialized != null).map((c) => c.name)
1279
+ ),
1280
+ defaults: new Set(
1281
+ columns.filter((c) => c.default != null).map((c) => c.name)
1282
+ )
1283
+ };
1284
+ const insertValidatorsObject = factory.createObjectLiteralExpression(
1285
+ [
1286
+ factory.createPropertyAssignment(
1287
+ factory.createIdentifier("validate"),
1288
+ wrapValidateFunction(
1289
+ generateInsertValidateFunction(
1290
+ typiaCtx,
1291
+ typeAtLocation,
1292
+ insertColumnSets
1293
+ )
1294
+ )
1295
+ ),
1296
+ factory.createPropertyAssignment(
1297
+ factory.createIdentifier("assert"),
1298
+ generateInsertAssertFunction(
1299
+ typiaCtx,
1300
+ typeAtLocation,
1301
+ insertColumnSets
1302
+ )
1303
+ ),
1304
+ factory.createPropertyAssignment(
1305
+ factory.createIdentifier("is"),
1306
+ generateInsertIsFunction(
1307
+ typiaCtx,
1308
+ typeAtLocation,
1309
+ insertColumnSets
1310
+ )
1311
+ )
1312
+ ],
1313
+ true
1314
+ );
1315
+ updatedArgs = [...updatedArgs, insertValidatorsObject];
1316
+ }
1233
1317
  if (resourceName === "IngestPipeline") {
1234
1318
  updatedArgs = [
1235
1319
  ...updatedArgs,