@flusys/nestjs-entity-builder 9.0.1 → 9.1.0

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.
Files changed (40) hide show
  1. package/README.md +22 -28
  2. package/config/message-keys.d.ts +9 -62
  3. package/controllers/flow-api-key.controller.d.ts +14 -0
  4. package/controllers/flow-definition.controller.d.ts +1 -7
  5. package/controllers/index.d.ts +1 -0
  6. package/dtos/flow.dto.d.ts +20 -10
  7. package/entities/flow-api-key.entity.d.ts +10 -0
  8. package/entities/flow-definition.entity.d.ts +9 -3
  9. package/entities/flow-execution.entity.d.ts +0 -1
  10. package/entities/index.d.ts +3 -3
  11. package/fesm/21.js +11 -64
  12. package/fesm/{582.js → 489.js} +11 -20
  13. package/fesm/{913.js → 606.js} +295 -209
  14. package/fesm/719.js +186 -162
  15. package/fesm/794.js +187 -116
  16. package/fesm/{677.js → 996.js} +616 -1490
  17. package/fesm/controllers/index.js +6 -5
  18. package/fesm/docs/index.js +2 -2
  19. package/fesm/entities/index.js +2 -2
  20. package/fesm/guards/index.js +19 -12
  21. package/fesm/index.js +638 -50
  22. package/fesm/modules/index.js +625 -7
  23. package/fesm/rule-engine/index.js +2 -2
  24. package/fesm/services/index.js +25 -54
  25. package/flow-engine/flow-api-key.d.ts +7 -3
  26. package/flow-engine/flow-graph.validator.d.ts +2 -4
  27. package/flow-engine/flow-run.types.d.ts +4 -14
  28. package/flow-engine/flow.types.d.ts +9 -91
  29. package/interfaces/flow-definition.interface.d.ts +9 -13
  30. package/package.json +5 -5
  31. package/rule-engine/rule-engine.service.d.ts +0 -1
  32. package/services/entity-flow-scaffold.d.ts +1 -1
  33. package/services/flow-api-key.service.d.ts +31 -0
  34. package/services/flow-definition.service.d.ts +12 -24
  35. package/services/flow-execution.service.d.ts +0 -1
  36. package/services/flow-executor.service.d.ts +7 -7
  37. package/services/generic-entity.service.d.ts +1 -1
  38. package/services/index.d.ts +1 -0
  39. package/entities/flow-version.entity.d.ts +0 -10
  40. package/fesm/458.js +0 -649
package/fesm/719.js CHANGED
@@ -198,7 +198,7 @@ const INPUT_TYPE = {
198
198
  [_enums_field_type_enum_js__rspack_import_1/* .FieldType.MULTI_SELECT */.P.MULTI_SELECT]: 'array',
199
199
  [_enums_field_type_enum_js__rspack_import_1/* .FieldType.RELATION */.P.RELATION]: 'uuid',
200
200
  [_enums_field_type_enum_js__rspack_import_1/* .FieldType.JSON */.P.JSON]: 'object',
201
- [_enums_field_type_enum_js__rspack_import_1/* .FieldType.FILE */.P.FILE]: 'uuid'
201
+ [_enums_field_type_enum_js__rspack_import_1/* .FieldType.FILE */.P.FILE]: 'string'
202
202
  };
203
203
  const LIST_LIMIT = 50;
204
204
  const READ_ENDPOINTS = new Set([
@@ -207,6 +207,7 @@ const READ_ENDPOINTS = new Set([
207
207
  'getAll',
208
208
  'getByFilter'
209
209
  ]);
210
+ /** A bulk flow runs up to three steps per item (bulkUpsert: check, write, keep), well inside FLOW_LIMITS.MAX_STEPS_PER_RUN. */ const BULK_MAX_ITEMS = 200;
210
211
  const COLUMN = {
211
212
  x: 40,
212
213
  gap: 300
@@ -227,56 +228,16 @@ const lit = (value)=>({
227
228
  function optionValues(options) {
228
229
  return (options ?? []).map((o)=>o && typeof o === 'object' && 'value' in o ? String(o.value) : String(o));
229
230
  }
230
- const NUMERIC_TYPES = new Set([
231
- _enums_field_type_enum_js__rspack_import_1/* .FieldType.INTEGER */.P.INTEGER,
232
- _enums_field_type_enum_js__rspack_import_1/* .FieldType.DECIMAL */.P.DECIMAL
233
- ]);
234
- const TEXT_TYPES = new Set([
235
- _enums_field_type_enum_js__rspack_import_1/* .FieldType.TEXT */.P.TEXT,
236
- _enums_field_type_enum_js__rspack_import_1/* .FieldType.LONG_TEXT */.P.LONG_TEXT,
237
- _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL
238
- ]);
239
- /** The field's rules a Request body checks the same way the record write does. */ function inputRules(field) {
240
- const rules = field.validationRules ?? {};
241
- const keys = NUMERIC_TYPES.has(field.fieldType) ? [
242
- 'min',
243
- 'max'
244
- ] : TEXT_TYPES.has(field.fieldType) ? [
245
- 'minLength',
246
- 'maxLength'
247
- ] : [];
248
- return Object.fromEntries(keys.filter((key)=>typeof rules[key] === 'number' && Number.isFinite(rules[key])).map((key)=>[
249
- key,
250
- rules[key]
251
- ]));
252
- }
253
- /**
254
- * The Request body input of a field: a choice carries its options, a multi-select is a list of
255
- * those choices, a relation or file is an id. `rules`: a write also checks the field's own value rules.
256
- */ function fieldInput(field, required, rules = true) {
231
+ function fieldInput(field, required) {
257
232
  const options = optionValues(field.selectOptions);
258
- const base = {
233
+ const type = INPUT_TYPE[field.fieldType] === 'choice' && !options.length ? 'string' : INPUT_TYPE[field.fieldType];
234
+ return {
259
235
  name: field.code,
260
236
  label: field.label || field.code,
237
+ type,
261
238
  ...required ? {
262
239
  required: true
263
240
  } : {},
264
- ...rules ? inputRules(field) : {}
265
- };
266
- if (field.fieldType === _enums_field_type_enum_js__rspack_import_1/* .FieldType.MULTI_SELECT */.P.MULTI_SELECT) return {
267
- ...base,
268
- type: 'array',
269
- ...options.length ? {
270
- itemType: 'choice',
271
- options
272
- } : {
273
- itemType: 'string'
274
- }
275
- };
276
- const type = INPUT_TYPE[field.fieldType] === 'choice' && !options.length ? 'string' : INPUT_TYPE[field.fieldType];
277
- return {
278
- ...base,
279
- type,
280
241
  ...type === 'choice' ? {
281
242
  options
282
243
  } : {}
@@ -288,7 +249,6 @@ const fieldMap = (fields, scope)=>Object.fromEntries(fields.map((f)=>[
288
249
  ref(`${scope}.${f.code}`)
289
250
  ]));
290
251
  const optionalFieldInputs = (fields)=>fields.map((f)=>fieldInput(f, false));
291
- /** Inputs of a read filter: only the value's type is checked, never the write rules. */ const filterInputs = (fields)=>fields.map((f)=>fieldInput(f, false, false));
292
252
  /** Fields an equality filter can match - a list or JSON value cannot be compared as one value. */ const filterableFields = (entity)=>entity.fields.filter((f)=>f.fieldType !== _enums_field_type_enum_js__rspack_import_1/* .FieldType.MULTI_SELECT */.P.MULTI_SELECT && f.fieldType !== _enums_field_type_enum_js__rspack_import_1/* .FieldType.JSON */.P.JSON);
293
253
  const idInput = (t)=>({
294
254
  name: 'id',
@@ -318,9 +278,8 @@ const respond = (id, column, statusCode, body, row)=>({
318
278
  });
319
279
  /**
320
280
  * The steps of one endpoint. Its step ids are `<endpoint>_<step>` (`id()`), so the endpoints of one
321
- * flow never share a step. A bulk body is the list itself (`itemSchema` checks each item), written by
322
- * one step that walks it (`target: many`, each item read as `loop.item`), all or nothing, and
323
- * answered with the saved records in order.
281
+ * flow never share a step. A bulk body is the list itself (`itemSchema` checks each item):
282
+ * foreach `input` -> `body` (per item) ... done -> respond with the collected results.
324
283
  */ function endpointGraph(entity, endpoint, texts) {
325
284
  const id = (step)=>`${endpoint}_${step}`;
326
285
  const entityCode = entity.code;
@@ -342,26 +301,33 @@ const respond = (id, column, statusCode, body, row)=>({
342
301
  ]
343
302
  ]
344
303
  });
345
- const bulk = (itemSchema, step, statusCode)=>({
304
+ const bulk = (itemSchema, body, bodyEdges, collect, statusCode)=>({
346
305
  bodyType: 'list',
347
306
  inputSchema: itemSchema,
348
307
  steps: [
349
308
  {
350
- ...step,
351
- id: id('records'),
309
+ id: id('each'),
310
+ type: 'foreach',
352
311
  column: 1,
353
312
  config: {
354
- ...step.config,
355
- target: 'many',
356
- items: ref('input')
313
+ items: ref('input'),
314
+ maxItems: BULK_MAX_ITEMS,
315
+ collect
357
316
  }
358
317
  },
359
- respond(id('respond'), 2, statusCode, ref(`context.${id('records')}.items`))
318
+ ...body,
319
+ respond(id('respond'), 2, statusCode, ref(`context.${id('each')}.results`))
360
320
  ],
361
321
  edges: [
362
322
  [
363
- id('records'),
364
- 'out',
323
+ id('each'),
324
+ 'each',
325
+ body[0].id
326
+ ],
327
+ ...bodyEdges,
328
+ [
329
+ id('each'),
330
+ 'done',
365
331
  id('respond')
366
332
  ]
367
333
  ]
@@ -378,13 +344,18 @@ const respond = (id, column, statusCode, body, row)=>({
378
344
  }
379
345
  }, 201);
380
346
  case 'insertMany':
381
- return bulk(insertInputs, {
382
- type: 'entity_insert',
383
- config: {
384
- entityCode,
385
- fields: fieldMap(entity.fields, 'loop.item')
347
+ return bulk(insertInputs, [
348
+ {
349
+ id: id('record'),
350
+ type: 'entity_insert',
351
+ column: 1,
352
+ row: 1,
353
+ config: {
354
+ entityCode,
355
+ fields: fieldMap(entity.fields, 'loop.item')
356
+ }
386
357
  }
387
- }, 201);
358
+ ], [], ref(`context.${id('record')}`), 201);
388
359
  case 'getById':
389
360
  return single([
390
361
  idInput(texts)
@@ -418,7 +389,7 @@ const respond = (id, column, statusCode, body, row)=>({
418
389
  label: texts.inputLabels.search,
419
390
  type: 'string'
420
391
  },
421
- ...filterInputs(filterFields)
392
+ ...optionalFieldInputs(filterFields)
422
393
  ], {
423
394
  type: 'entity_query',
424
395
  config: {
@@ -435,7 +406,7 @@ const respond = (id, column, statusCode, body, row)=>({
435
406
  ...idInput(texts),
436
407
  required: false
437
408
  },
438
- ...filterInputs(filterFields)
409
+ ...optionalFieldInputs(filterFields)
439
410
  ],
440
411
  steps: [
441
412
  {
@@ -508,13 +479,19 @@ const respond = (id, column, statusCode, body, row)=>({
508
479
  return bulk([
509
480
  idInput(texts),
510
481
  ...optionalFieldInputs(entity.fields)
511
- ], {
512
- type: 'entity_update',
513
- config: {
514
- entityCode,
515
- fields: fieldMap(entity.fields, 'loop.item')
482
+ ], [
483
+ {
484
+ id: id('record'),
485
+ type: 'entity_update',
486
+ column: 1,
487
+ row: 1,
488
+ config: {
489
+ entityCode,
490
+ id: ref('loop.item.id'),
491
+ fields: fieldMap(entity.fields, 'loop.item')
492
+ }
516
493
  }
517
- }, 200);
494
+ ], [], ref(`context.${id('record')}`), 200);
518
495
  case 'bulkUpsert':
519
496
  return bulk([
520
497
  {
@@ -522,14 +499,89 @@ const respond = (id, column, statusCode, body, row)=>({
522
499
  required: false
523
500
  },
524
501
  ...optionalFieldInputs(entity.fields)
525
- ], {
526
- type: 'entity_update',
527
- config: {
528
- entityCode,
529
- fields: fieldMap(entity.fields, 'loop.item'),
530
- onNotFound: 'insert'
502
+ ], [
503
+ {
504
+ id: id('has_id'),
505
+ type: 'condition',
506
+ column: 1,
507
+ row: 1,
508
+ config: {
509
+ rule: {
510
+ operator: 'AND',
511
+ conditions: [
512
+ {
513
+ field: 'loop.item.id',
514
+ comparison: 'is_not_empty'
515
+ }
516
+ ]
517
+ }
518
+ }
519
+ },
520
+ {
521
+ id: id('updated'),
522
+ type: 'entity_update',
523
+ column: 2,
524
+ row: 1,
525
+ config: {
526
+ entityCode,
527
+ id: ref('loop.item.id'),
528
+ fields: fieldMap(entity.fields, 'loop.item')
529
+ }
530
+ },
531
+ {
532
+ id: id('inserted'),
533
+ type: 'entity_insert',
534
+ column: 2,
535
+ row: 2,
536
+ config: {
537
+ entityCode,
538
+ fields: fieldMap(entity.fields, 'loop.item')
539
+ }
540
+ },
541
+ {
542
+ id: id('keep_updated'),
543
+ type: 'set',
544
+ column: 3,
545
+ row: 1,
546
+ config: {
547
+ values: {
548
+ saved: ref(`context.${id('updated')}`)
549
+ }
550
+ }
551
+ },
552
+ {
553
+ id: id('keep_inserted'),
554
+ type: 'set',
555
+ column: 3,
556
+ row: 2,
557
+ config: {
558
+ values: {
559
+ saved: ref(`context.${id('inserted')}`)
560
+ }
561
+ }
531
562
  }
532
- }, 200);
563
+ ], [
564
+ [
565
+ id('has_id'),
566
+ 'true',
567
+ id('updated')
568
+ ],
569
+ [
570
+ id('has_id'),
571
+ 'false',
572
+ id('inserted')
573
+ ],
574
+ [
575
+ id('updated'),
576
+ 'out',
577
+ id('keep_updated')
578
+ ],
579
+ [
580
+ id('inserted'),
581
+ 'out',
582
+ id('keep_inserted')
583
+ ]
584
+ ], ref('vars.saved'), 200);
533
585
  case 'delete':
534
586
  return single([
535
587
  idInput(texts)
@@ -545,11 +597,10 @@ const respond = (id, column, statusCode, body, row)=>({
545
597
  /**
546
598
  * The ready-made flow of an entity: `api-flows/<entity>` with one Request step per endpoint of the
547
599
  * generic API controller, each on its own path (`ENTITY_FLOW_PATHS`) with its own body, laid out
548
- * one below the other. Each runs as the caller, so the entity permissions still decide who may use
600
+ * one below the other. It runs as the caller, so the entity permissions still decide who may use
549
601
  * it, and it is an ordinary flow afterwards - the user can change or delete it like any other. A
550
- * write endpoint is transactional: a bulk endpoint writes its whole list in one step, so a failing
551
- * item rolls back the whole request; a read endpoint opens none. A bulk body holds at most
552
- * FLOW_LIMITS.MAX_WRITE_ITEMS items.
602
+ * flow with a write endpoint is transactional: a bulk endpoint loops over its list in one
603
+ * transaction, so a failing item rolls back the whole request.
553
604
  */ function buildEntityFlow(entity, endpoints, texts = {}) {
554
605
  const resolved = {
555
606
  inputLabels: {
@@ -571,10 +622,7 @@ const respond = (id, column, statusCode, body, row)=>({
571
622
  const config = {
572
623
  path: ENTITY_FLOW_PATHS[endpoint],
573
624
  bodyType: graph.bodyType ?? 'object',
574
- inputSchema: graph.inputSchema,
575
- ...READ_ENDPOINTS.has(endpoint) ? {} : {
576
- isTransactional: true
577
- }
625
+ inputSchema: graph.inputSchema
578
626
  };
579
627
  nodes.push({
580
628
  id: endpoint,
@@ -606,6 +654,11 @@ const respond = (id, column, statusCode, body, row)=>({
606
654
  name: entity.label.slice(0, MAX_NAME_LENGTH),
607
655
  slug: entityFlowSlug(entity.code),
608
656
  isActive: true,
657
+ authMode: 'jwt',
658
+ runAs: 'caller',
659
+ isTransactional: endpoints.some((endpoint)=>!READ_ENDPOINTS.has(endpoint)),
660
+ bodyType: 'object',
661
+ inputSchema: [],
609
662
  nodes,
610
663
  edges
611
664
  };
@@ -2113,12 +2166,7 @@ class SchemaEvolutionService {
2113
2166
  const nullable = spec.nullable ?? true;
2114
2167
  const unique = spec.unique ?? false;
2115
2168
  const dbType = this.adapter.mapFieldType(spec.fieldType, ctx.driver);
2116
- const isRelation = spec.fieldType === _enums_field_type_enum_js__rspack_import_20/* .FieldType.RELATION */.P.RELATION;
2117
- if (isRelation && !spec.relationTargetEntityId) {
2118
- ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_19/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_REQUIRED */.M3.RELATION_TARGET_REQUIRED, {
2119
- field: spec.code
2120
- }));
2121
- } else if (isRelation) {
2169
+ if (spec.relationTargetEntityId) {
2122
2170
  const target = await ctx.qr.manager.getRepository(_entities_entity_definition_entity_js__rspack_import_7/* .EntityDefinition */.f).findOne({
2123
2171
  where: {
2124
2172
  id: spec.relationTargetEntityId
@@ -2158,8 +2206,8 @@ class SchemaEvolutionService {
2158
2206
  }));
2159
2207
  }
2160
2208
  }
2161
- // Only a required field is backfilled; every existing row gets the same value, so two rows or more would clash.
2162
- if (unique && !nullable && backfill !== null && rows > 1) {
2209
+ // Every existing row gets the same backfill value, so two rows or more would clash.
2210
+ if (unique && backfill !== null && rows > 1) {
2163
2211
  ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_19/* .SCHEMA_BLOCKER_MESSAGES.UNIQUE_BACKFILL_CONFLICT */.M3.UNIQUE_BACKFILL_CONFLICT));
2164
2212
  }
2165
2213
  if (ctx.blocked || !table) {
@@ -2224,7 +2272,7 @@ class SchemaEvolutionService {
2224
2272
  defaultValue: spec.defaultValue ?? null,
2225
2273
  validationRules: spec.validationRules ?? null,
2226
2274
  selectOptions: spec.selectOptions ?? null,
2227
- relationTargetEntityId: isRelation ? spec.relationTargetEntityId : null,
2275
+ relationTargetEntityId: spec.relationTargetEntityId ?? null,
2228
2276
  order: spec.order ?? Math.max(-1, ...fields.map((f)=>f.order)) + 1,
2229
2277
  uiConfig: spec.uiConfig ?? null,
2230
2278
  isSearchable: spec.isSearchable ?? false,
@@ -3240,23 +3288,21 @@ __webpack_require__.d(__webpack_exports__, {
3240
3288
  /* import */ var _flusys_nestjs_shared_utils__rspack_import_1 = __webpack_require__(9216);
3241
3289
  /* import */ var _nestjs_common__rspack_import_2 = __webpack_require__(6157);
3242
3290
  /* import */ var typeorm__rspack_import_3 = __webpack_require__(7158);
3243
- /* import */ var _config_message_keys_js__rspack_import_17 = __webpack_require__(5732);
3291
+ /* import */ var _config_message_keys_js__rspack_import_16 = __webpack_require__(5732);
3244
3292
  /* import */ var _entities_entity_definition_entity_js__rspack_import_4 = __webpack_require__(3189);
3245
3293
  /* import */ var _entities_field_definition_entity_js__rspack_import_5 = __webpack_require__(2206);
3246
3294
  /* import */ var _entities_flow_definition_entity_js__rspack_import_6 = __webpack_require__(3770);
3247
- /* import */ var _enums_ddl_operation_enum_js__rspack_import_20 = __webpack_require__(9949);
3248
- /* import */ var _enums_entity_status_enum_js__rspack_import_21 = __webpack_require__(1313);
3249
- /* import */ var _enums_field_type_enum_js__rspack_import_19 = __webpack_require__(9614);
3295
+ /* import */ var _enums_ddl_operation_enum_js__rspack_import_18 = __webpack_require__(9949);
3296
+ /* import */ var _enums_entity_status_enum_js__rspack_import_19 = __webpack_require__(1313);
3250
3297
  /* import */ var _flow_engine_flow_errors_js__rspack_import_7 = __webpack_require__(8542);
3251
3298
  /* import */ var _entity_builder_datasource_provider_js__rspack_import_8 = __webpack_require__(424);
3252
3299
  /* import */ var _entity_flow_scaffold_js__rspack_import_9 = __webpack_require__(8271);
3253
3300
  /* import */ var _entity_permission_service_js__rspack_import_10 = __webpack_require__(1462);
3254
- /* import */ var _field_value_validator_js__rspack_import_11 = __webpack_require__(3525);
3255
- /* import */ var _flow_definition_service_js__rspack_import_12 = __webpack_require__(4921);
3256
- /* import */ var _identifier_rules_js__rspack_import_13 = __webpack_require__(413);
3257
- /* import */ var _schema_change_executor_service_js__rspack_import_14 = __webpack_require__(6605);
3258
- /* import */ var _schema_columns_js__rspack_import_15 = __webpack_require__(5313);
3259
- /* import */ var _schema_dialect_adapter_service_js__rspack_import_16 = __webpack_require__(7259);
3301
+ /* import */ var _flow_definition_service_js__rspack_import_11 = __webpack_require__(5229);
3302
+ /* import */ var _identifier_rules_js__rspack_import_12 = __webpack_require__(413);
3303
+ /* import */ var _schema_change_executor_service_js__rspack_import_13 = __webpack_require__(6605);
3304
+ /* import */ var _schema_columns_js__rspack_import_14 = __webpack_require__(5313);
3305
+ /* import */ var _schema_dialect_adapter_service_js__rspack_import_15 = __webpack_require__(7259);
3260
3306
  function _ts_decorate(decorators, target, key, desc) {
3261
3307
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3262
3308
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -3298,8 +3344,6 @@ function _ts_param(paramIndex, decorator) {
3298
3344
 
3299
3345
 
3300
3346
 
3301
-
3302
-
3303
3347
 
3304
3348
 
3305
3349
  class SchemaSyncService {
@@ -3317,17 +3361,17 @@ class SchemaSyncService {
3317
3361
  this.flowDefinitionService = flowDefinitionService;
3318
3362
  }
3319
3363
  validateCreateRequest(dto) {
3320
- (0,_identifier_rules_js__rspack_import_13/* .assertValidIdentifier */.kV)(dto.code, 'entity');
3364
+ (0,_identifier_rules_js__rspack_import_12/* .assertValidIdentifier */.kV)(dto.code, 'entity');
3321
3365
  const fields = dto.fields ?? [];
3322
3366
  for (const field of fields){
3323
- (0,_identifier_rules_js__rspack_import_13/* .assertValidIdentifier */.kV)(field.code, 'field');
3324
- (0,_identifier_rules_js__rspack_import_13/* .assertIndexableField */.fY)(field);
3367
+ (0,_identifier_rules_js__rspack_import_12/* .assertValidIdentifier */.kV)(field.code, 'field');
3368
+ (0,_identifier_rules_js__rspack_import_12/* .assertIndexableField */.fY)(field);
3325
3369
  }
3326
3370
  const duplicate = fields.map((f)=>f.code).find((code, index, all)=>all.indexOf(code) !== index);
3327
3371
  if (duplicate) {
3328
3372
  throw new _nestjs_common__rspack_import_2.BadRequestException({
3329
3373
  message: `Field code '${duplicate}' is defined more than once.`,
3330
- messageKey: _config_message_keys_js__rspack_import_17/* .SCHEMA_MESSAGES.DUPLICATE_FIELD_CODE */.Hu.DUPLICATE_FIELD_CODE,
3374
+ messageKey: _config_message_keys_js__rspack_import_16/* .SCHEMA_MESSAGES.DUPLICATE_FIELD_CODE */.Hu.DUPLICATE_FIELD_CODE,
3331
3375
  messageVariables: {
3332
3376
  code: duplicate
3333
3377
  }
@@ -3335,7 +3379,7 @@ class SchemaSyncService {
3335
3379
  }
3336
3380
  }
3337
3381
  async createTarget(dto, user) {
3338
- const lockCodes = await (0,_schema_change_executor_service_js__rspack_import_14/* .relationTargetCodes */.e)(this.dataSourceProvider, (dto.fields ?? []).map((f)=>f.relationTargetEntityId));
3382
+ const lockCodes = await (0,_schema_change_executor_service_js__rspack_import_13/* .relationTargetCodes */.e)(this.dataSourceProvider, (dto.fields ?? []).map((f)=>f.relationTargetEntityId));
3339
3383
  return {
3340
3384
  action: 'create_entity',
3341
3385
  entityDefinitionId: null,
@@ -3356,7 +3400,7 @@ class SchemaSyncService {
3356
3400
  const taken = await ctx.qr.query((0,_flusys_nestjs_shared_classes__rspack_import_0.buildQuery)(`SELECT table_name FROM information_schema.tables WHERE table_schema = ${schemaExpr} AND table_name = ?`, ctx.driver), [
3357
3401
  tableName
3358
3402
  ]);
3359
- if (taken.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.TABLE_EXISTS */.M3.TABLE_EXISTS, {
3403
+ if (taken.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_BLOCKER_MESSAGES.TABLE_EXISTS */.M3.TABLE_EXISTS, {
3360
3404
  table: tableName
3361
3405
  }));
3362
3406
  const definitions = ctx.qr.manager.getRepository(_entities_entity_definition_entity_js__rspack_import_4/* .EntityDefinition */.f);
@@ -3365,41 +3409,21 @@ class SchemaSyncService {
3365
3409
  code: dto.code
3366
3410
  }
3367
3411
  });
3368
- if (known) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.ENTITY_CODE_EXISTS */.M3.ENTITY_CODE_EXISTS, {
3412
+ if (known) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_BLOCKER_MESSAGES.ENTITY_CODE_EXISTS */.M3.ENTITY_CODE_EXISTS, {
3369
3413
  code: dto.code
3370
3414
  }));
3371
- for (const spec of fieldSpecs.filter((f)=>f.fieldType === _enums_field_type_enum_js__rspack_import_19/* .FieldType.RELATION */.P.RELATION)){
3372
- if (!spec.relationTargetEntityId) {
3373
- ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_REQUIRED */.M3.RELATION_TARGET_REQUIRED, {
3415
+ for (const spec of fieldSpecs){
3416
+ if (spec.relationTargetEntityId) {
3417
+ const target = await definitions.findOne({
3418
+ where: {
3419
+ id: spec.relationTargetEntityId
3420
+ }
3421
+ });
3422
+ if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_BLOCKER_MESSAGES.RELATION_FIELD_TARGET_MISSING */.M3.RELATION_FIELD_TARGET_MISSING, {
3374
3423
  field: spec.code
3375
3424
  }));
3376
- continue;
3377
3425
  }
3378
- const target = await definitions.findOne({
3379
- where: {
3380
- id: spec.relationTargetEntityId
3381
- }
3382
- });
3383
- if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.RELATION_FIELD_TARGET_MISSING */.M3.RELATION_FIELD_TARGET_MISSING, {
3384
- field: spec.code
3385
- }));
3386
3426
  }
3387
- const withDefault = fieldSpecs.filter((f)=>f.defaultValue !== undefined && f.defaultValue !== null);
3388
- const { errors: defaultErrors } = (0,_field_value_validator_js__rspack_import_11/* .validateRecord */.e)(withDefault.map((f)=>({
3389
- code: f.code,
3390
- label: f.label,
3391
- fieldType: f.fieldType,
3392
- nullable: true,
3393
- defaultValue: null,
3394
- selectOptions: f.selectOptions ?? null,
3395
- validationRules: f.validationRules ?? null
3396
- })), Object.fromEntries(withDefault.map((f)=>[
3397
- f.code,
3398
- f.defaultValue
3399
- ])), 'insert');
3400
- for (const error of defaultErrors)ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.DEFAULT_INVALID */.M3.DEFAULT_INVALID, {
3401
- problem: (0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(error.messageKey, error.messageVariables)
3402
- }));
3403
3427
  if (flowEndpoints.length) {
3404
3428
  const slug = (0,_entity_flow_scaffold_js__rspack_import_9/* .entityFlowSlug */.x2)(dto.code);
3405
3429
  const clash = await ctx.qr.manager.getRepository(_entities_flow_definition_entity_js__rspack_import_6/* .FlowDefinition */.G).findOne({
@@ -3411,15 +3435,15 @@ class SchemaSyncService {
3411
3435
  },
3412
3436
  withDeleted: true
3413
3437
  });
3414
- if (clash) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.FLOW_SLUG_TAKEN */.M3.FLOW_SLUG_TAKEN, {
3438
+ if (clash) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_BLOCKER_MESSAGES.FLOW_SLUG_TAKEN */.M3.FLOW_SLUG_TAKEN, {
3415
3439
  slug
3416
3440
  }));
3417
3441
  }
3418
3442
  if (ctx.blocked) return {
3419
- operation: _enums_ddl_operation_enum_js__rspack_import_20/* .DdlOperation.CREATE_TABLE */.i.CREATE_TABLE,
3443
+ operation: _enums_ddl_operation_enum_js__rspack_import_18/* .DdlOperation.CREATE_TABLE */.i.CREATE_TABLE,
3420
3444
  diff: {}
3421
3445
  };
3422
- const columns = fieldSpecs.map((spec)=>(0,_schema_columns_js__rspack_import_15/* .buildFieldColumn */.fu)({
3446
+ const columns = fieldSpecs.map((spec)=>(0,_schema_columns_js__rspack_import_14/* .buildFieldColumn */.fu)({
3423
3447
  code: spec.code,
3424
3448
  fieldType: spec.fieldType,
3425
3449
  dbType: '',
@@ -3432,23 +3456,23 @@ class SchemaSyncService {
3432
3456
  const table = new typeorm__rspack_import_3.Table({
3433
3457
  name: tableName,
3434
3458
  columns: [
3435
- ...(0,_schema_columns_js__rspack_import_15/* .buildSystemColumns */.Rm)({
3459
+ ...(0,_schema_columns_js__rspack_import_14/* .buildSystemColumns */.Rm)({
3436
3460
  isSoftDeleteEnabled,
3437
3461
  isAuditEnabled
3438
3462
  }, ctx.driver),
3439
3463
  ...columns
3440
3464
  ]
3441
3465
  });
3442
- await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_STEP_MESSAGES.CREATE_TABLE */.EQ.CREATE_TABLE, {
3466
+ await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_STEP_MESSAGES.CREATE_TABLE */.EQ.CREATE_TABLE, {
3443
3467
  table: tableName
3444
3468
  }), async ()=>{
3445
3469
  await ctx.qr.createTable(table, false);
3446
3470
  });
3447
3471
  for (const spec of fieldSpecs.filter((f)=>f.isIndexed && !f.unique)){
3448
- await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_STEP_MESSAGES.ADD_INDEX */.EQ.ADD_INDEX, {
3472
+ await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_STEP_MESSAGES.ADD_INDEX */.EQ.ADD_INDEX, {
3449
3473
  column: spec.code
3450
3474
  }), async ()=>{
3451
- await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_15/* .plainIndex */.v7)(tableName, spec.code, ctx.driver, this.dialectAdapter));
3475
+ await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_14/* .plainIndex */.v7)(tableName, spec.code, ctx.driver, this.dialectAdapter));
3452
3476
  });
3453
3477
  }
3454
3478
  await ctx.metadata(async ()=>{
@@ -3458,7 +3482,7 @@ class SchemaSyncService {
3458
3482
  label: dto.label,
3459
3483
  description: dto.description ?? null,
3460
3484
  tableName,
3461
- status: _enums_entity_status_enum_js__rspack_import_21/* .EntityStatus.ACTIVE */.c.ACTIVE,
3485
+ status: _enums_entity_status_enum_js__rspack_import_19/* .EntityStatus.ACTIVE */.c.ACTIVE,
3462
3486
  schemaVersion: 1,
3463
3487
  isSoftDeleteEnabled,
3464
3488
  isAuditEnabled,
@@ -3478,7 +3502,7 @@ class SchemaSyncService {
3478
3502
  defaultValue: spec.defaultValue ?? null,
3479
3503
  validationRules: spec.validationRules ?? null,
3480
3504
  selectOptions: spec.selectOptions ?? null,
3481
- relationTargetEntityId: spec.fieldType === _enums_field_type_enum_js__rspack_import_19/* .FieldType.RELATION */.P.RELATION ? spec.relationTargetEntityId : null,
3505
+ relationTargetEntityId: spec.relationTargetEntityId ?? null,
3482
3506
  order: spec.order ?? index,
3483
3507
  uiConfig: spec.uiConfig ?? null,
3484
3508
  isSearchable: spec.isSearchable ?? false,
@@ -3489,7 +3513,7 @@ class SchemaSyncService {
3489
3513
  created.definition = definition;
3490
3514
  });
3491
3515
  return {
3492
- operation: _enums_ddl_operation_enum_js__rspack_import_20/* .DdlOperation.CREATE_TABLE */.i.CREATE_TABLE,
3516
+ operation: _enums_ddl_operation_enum_js__rspack_import_18/* .DdlOperation.CREATE_TABLE */.i.CREATE_TABLE,
3493
3517
  entityDefinitionId: created.definition?.id ?? null,
3494
3518
  diff: {
3495
3519
  fields: fieldSpecs.map((f)=>({
@@ -3525,7 +3549,7 @@ class SchemaSyncService {
3525
3549
  } catch (error) {
3526
3550
  this.logger.error(`The flow '${flow.slug}' of entity '${dto.code}' could not be created: ${error.message}`);
3527
3551
  return [
3528
- (0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_17/* .SCHEMA_WARNING_MESSAGES.ENDPOINT_FLOW_FAILED */.Uu.ENDPOINT_FLOW_FAILED, {
3552
+ (0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_16/* .SCHEMA_WARNING_MESSAGES.ENDPOINT_FLOW_FAILED */.Uu.ENDPOINT_FLOW_FAILED, {
3529
3553
  slug: flow.slug,
3530
3554
  detail: (0,_flow_engine_flow_errors_js__rspack_import_7/* .errorRef */.O$)(error)
3531
3555
  })
@@ -3548,10 +3572,10 @@ class SchemaSyncService {
3548
3572
  try {
3549
3573
  ({ plan: { warnings: planWarnings } } = await this.executor.apply(await this.createTarget(dto, user), this.createRun(dto, user, created)));
3550
3574
  } catch (error) {
3551
- if (error instanceof _nestjs_common__rspack_import_2.ConflictException && error.getResponse().blockers?.some((b)=>b.messageKey === _config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.ENTITY_CODE_EXISTS */.M3.ENTITY_CODE_EXISTS || b.messageKey === _config_message_keys_js__rspack_import_17/* .SCHEMA_BLOCKER_MESSAGES.TABLE_EXISTS */.M3.TABLE_EXISTS)) {
3575
+ if (error instanceof _nestjs_common__rspack_import_2.ConflictException && error.getResponse().blockers?.some((b)=>b.messageKey === _config_message_keys_js__rspack_import_16/* .SCHEMA_BLOCKER_MESSAGES.ENTITY_CODE_EXISTS */.M3.ENTITY_CODE_EXISTS || b.messageKey === _config_message_keys_js__rspack_import_16/* .SCHEMA_BLOCKER_MESSAGES.TABLE_EXISTS */.M3.TABLE_EXISTS)) {
3552
3576
  throw new _nestjs_common__rspack_import_2.ConflictException({
3553
3577
  message: `An entity with the code '${dto.code}' already exists.`,
3554
- messageKey: _config_message_keys_js__rspack_import_17/* .ENTITY_DEFINITION_MESSAGES.CODE_ALREADY_EXISTS */.pL.CODE_ALREADY_EXISTS,
3578
+ messageKey: _config_message_keys_js__rspack_import_16/* .ENTITY_DEFINITION_MESSAGES.CODE_ALREADY_EXISTS */.pL.CODE_ALREADY_EXISTS,
3555
3579
  messageVariables: {
3556
3580
  code: dto.code
3557
3581
  }
@@ -3573,17 +3597,17 @@ SchemaSyncService = _ts_decorate([
3573
3597
  scope: _nestjs_common__rspack_import_2.Scope.REQUEST
3574
3598
  }),
3575
3599
  _ts_param(0, (0,_nestjs_common__rspack_import_2.Inject)(_entity_builder_datasource_provider_js__rspack_import_8/* .EntityBuilderDataSourceProvider */.D)),
3576
- _ts_param(1, (0,_nestjs_common__rspack_import_2.Inject)(_schema_dialect_adapter_service_js__rspack_import_16/* .SchemaDialectAdapterService */.I)),
3577
- _ts_param(2, (0,_nestjs_common__rspack_import_2.Inject)(_schema_change_executor_service_js__rspack_import_14/* .SchemaChangeExecutor */.T)),
3600
+ _ts_param(1, (0,_nestjs_common__rspack_import_2.Inject)(_schema_dialect_adapter_service_js__rspack_import_15/* .SchemaDialectAdapterService */.I)),
3601
+ _ts_param(2, (0,_nestjs_common__rspack_import_2.Inject)(_schema_change_executor_service_js__rspack_import_13/* .SchemaChangeExecutor */.T)),
3578
3602
  _ts_param(3, (0,_nestjs_common__rspack_import_2.Inject)(_entity_permission_service_js__rspack_import_10/* .EntityPermissionService */.u)),
3579
- _ts_param(4, (0,_nestjs_common__rspack_import_2.Inject)(_flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk)),
3603
+ _ts_param(4, (0,_nestjs_common__rspack_import_2.Inject)(_flow_definition_service_js__rspack_import_11/* .FlowDefinitionService */.Tk)),
3580
3604
  _ts_metadata("design:type", Function),
3581
3605
  _ts_metadata("design:paramtypes", [
3582
3606
  typeof _entity_builder_datasource_provider_js__rspack_import_8/* .EntityBuilderDataSourceProvider */.D === "undefined" ? Object : _entity_builder_datasource_provider_js__rspack_import_8/* .EntityBuilderDataSourceProvider */.D,
3583
- typeof _schema_dialect_adapter_service_js__rspack_import_16/* .SchemaDialectAdapterService */.I === "undefined" ? Object : _schema_dialect_adapter_service_js__rspack_import_16/* .SchemaDialectAdapterService */.I,
3584
- typeof _schema_change_executor_service_js__rspack_import_14/* .SchemaChangeExecutor */.T === "undefined" ? Object : _schema_change_executor_service_js__rspack_import_14/* .SchemaChangeExecutor */.T,
3607
+ typeof _schema_dialect_adapter_service_js__rspack_import_15/* .SchemaDialectAdapterService */.I === "undefined" ? Object : _schema_dialect_adapter_service_js__rspack_import_15/* .SchemaDialectAdapterService */.I,
3608
+ typeof _schema_change_executor_service_js__rspack_import_13/* .SchemaChangeExecutor */.T === "undefined" ? Object : _schema_change_executor_service_js__rspack_import_13/* .SchemaChangeExecutor */.T,
3585
3609
  typeof _entity_permission_service_js__rspack_import_10/* .EntityPermissionService */.u === "undefined" ? Object : _entity_permission_service_js__rspack_import_10/* .EntityPermissionService */.u,
3586
- typeof _flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk === "undefined" ? Object : _flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk
3610
+ typeof _flow_definition_service_js__rspack_import_11/* .FlowDefinitionService */.Tk === "undefined" ? Object : _flow_definition_service_js__rspack_import_11/* .FlowDefinitionService */.Tk
3587
3611
  ])
3588
3612
  ], SchemaSyncService);
3589
3613