@izara_project/izara-core-generate-service-code 1.0.87 → 1.0.88

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.
@@ -42,6 +42,10 @@ test('emits CRUD handlers and function YAML from schema data without reading gen
42
42
  'utf8'
43
43
  );
44
44
  assert.match(createMain, /CreateLogicalLib/);
45
+ assert.match(
46
+ createMain,
47
+ /validateFieldNames\(_izContext, requestParams, objectSchemas, errorsFound\)/
48
+ );
45
49
  assert.doesNotMatch(createMain, /FlowHook|beforeLogical|codeHookTag/);
46
50
  const yaml = await readFile(
47
51
  join(rootPath, 'app/sls_yaml/generatedCode/source/flow-objects.yml'),
@@ -417,6 +421,533 @@ test('emits targetIdentifiers passed directly to checkRbacPermission options in
417
421
  assert.match(deleteMain, /checkRbacPermission\([\s\S]*targetIdentifiers,[\s\S]*rbacObjType/);
418
422
  });
419
423
 
424
+ test('emits synchronous after-hook invocation in CreateLogicalLib when codeHookTag is after and invocationType is lambdaSyncInv', async () => {
425
+ const rootPath = await createProject(true);
426
+ const schemas = join(rootPath, 'app/src/schemas');
427
+ await writeFile(
428
+ join(schemas, 'FlowSchemas/AuditAfterCreate.js'),
429
+ "export default { flowTag: 'auditAfterCreate', event: ['lambdaSyncInv'], generatedCodeConfig: { generateCodeTag: 'create', codeHookTag: 'after', invocationType: 'lambdaSyncInv', objType: { objectType: 'order' } } };\n"
430
+ );
431
+ const result = await generateCrudApplicationArtifacts(rootPath, {
432
+ serviceTag: 'orders'
433
+ });
434
+
435
+ const createLogicalLib = await readFile(
436
+ join(
437
+ rootPath,
438
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateLogicalLib.js'
439
+ ),
440
+ 'utf8'
441
+ );
442
+ assert.match(
443
+ createLogicalLib,
444
+ /lambda\.invokeSync\(\s*_izContext,\s*await lambdaSharedLib\.lambdaFunctionName\(\s*_izContext,\s*'auditAfterCreate'\s*\)/
445
+ );
446
+ assert.match(createLogicalLib, /Hook auditAfterCreate failed/);
447
+
448
+ execFileSync(
449
+ process.execPath,
450
+ [
451
+ '--check',
452
+ join(
453
+ rootPath,
454
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateLogicalLib.js'
455
+ )
456
+ ],
457
+ { stdio: 'inherit' }
458
+ );
459
+
460
+ assert.ok(result.files.every((f) => !f.path.includes('CreateAfterHookCallback')));
461
+ });
462
+
463
+ test('emits synchronous after-hook invocation in CreateNodeCallback_Main when object has graph and hook is sync', async () => {
464
+ const rootPath = await createRbacProject(false, true);
465
+ const schemas = join(rootPath, 'app/src/schemas');
466
+ await writeFile(
467
+ join(schemas, 'FlowSchemas/AuditAfterCreate.js'),
468
+ "export default { flowTag: 'auditAfterCreate', event: ['lambdaSyncInv'], generatedCodeConfig: { generateCodeTag: 'create', codeHookTag: 'after', invocationType: 'lambdaSyncInv', objType: { objectType: 'order' } } };\n"
469
+ );
470
+ await generateCrudApplicationArtifacts(rootPath, {
471
+ serviceTag: 'orders'
472
+ });
473
+
474
+ const nodeCallbackMain = await readFile(
475
+ join(
476
+ rootPath,
477
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateNodeCallback_Main.js'
478
+ ),
479
+ 'utf8'
480
+ );
481
+ assert.match(
482
+ nodeCallbackMain,
483
+ /lambda\.invokeSync\(\s*_izContext,\s*await lambdaSharedLib\.lambdaFunctionName\(\s*_izContext,\s*'auditAfterCreate'\s*\)/
484
+ );
485
+ assert.match(nodeCallbackMain, /Hook auditAfterCreate failed/);
486
+
487
+ execFileSync(
488
+ process.execPath,
489
+ [
490
+ '--check',
491
+ join(
492
+ rootPath,
493
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateNodeCallback_Main.js'
494
+ )
495
+ ],
496
+ { stdio: 'inherit' }
497
+ );
498
+ });
499
+
500
+ test('emits async after-hook callback and SNS publish in CreateLogicalLib and flow-objects.yml', async () => {
501
+ const rootPath = await createProject(true);
502
+ const schemas = join(rootPath, 'app/src/schemas');
503
+ await writeFile(
504
+ join(schemas, 'FlowSchemas/NotifyAfterCreate.js'),
505
+ "export default { flowTag: 'notifyAfterCreate', event: ['ownTopic'], generatedCodeConfig: { generateCodeTag: 'create', codeHookTag: 'after', invocationType: 'ownTopic', objType: { objectType: 'order' } } };\n"
506
+ );
507
+ const result = await generateCrudApplicationArtifacts(rootPath, {
508
+ serviceTag: 'orders'
509
+ });
510
+
511
+ const createLogicalLib = await readFile(
512
+ join(
513
+ rootPath,
514
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateLogicalLib.js'
515
+ ),
516
+ 'utf8'
517
+ );
518
+ assert.match(createLogicalLib, /sns\.publishAsync\(_izContext,/);
519
+ assert.match(
520
+ createLogicalLib,
521
+ /snsTopicArnByFlowSchema\(\s*_izContext,\s*'notifyAfterCreate_In'\s*\)/
522
+ );
523
+ assert.match(createLogicalLib, /CreateAfterHookCallbackHdrSqs/);
524
+
525
+ const afterHookMain = await readFile(
526
+ join(
527
+ rootPath,
528
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateAfterHookCallback_Main.js'
529
+ ),
530
+ 'utf8'
531
+ );
532
+ assert.match(
533
+ afterHookMain,
534
+ /export default async function CreateAfterHookCallbackMain/
535
+ );
536
+ assert.match(
537
+ afterHookMain,
538
+ /TOPIC_NAME_GENERATE_CODE\.outCreateNodeComplete/
539
+ );
540
+
541
+ const afterHookHdrSqs = await readFile(
542
+ join(
543
+ rootPath,
544
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateAfterHookCallback_HdrSqs.js'
545
+ ),
546
+ 'utf8'
547
+ );
548
+ assert.match(afterHookHdrSqs, /CreateAfterHookCallbackMain/);
549
+
550
+ execFileSync(
551
+ process.execPath,
552
+ [
553
+ '--check',
554
+ join(
555
+ rootPath,
556
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateAfterHookCallback_Main.js'
557
+ )
558
+ ],
559
+ { stdio: 'inherit' }
560
+ );
561
+ execFileSync(
562
+ process.execPath,
563
+ [
564
+ '--check',
565
+ join(
566
+ rootPath,
567
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateAfterHookCallback_HdrSqs.js'
568
+ )
569
+ ],
570
+ { stdio: 'inherit' }
571
+ );
572
+ execFileSync(
573
+ process.execPath,
574
+ [
575
+ '--check',
576
+ join(
577
+ rootPath,
578
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateLogicalLib.js'
579
+ )
580
+ ],
581
+ { stdio: 'inherit' }
582
+ );
583
+
584
+ const yaml = await readFile(
585
+ join(rootPath, 'app/sls_yaml/generatedCode/source/flow-objects.yml'),
586
+ 'utf8'
587
+ );
588
+ assert.match(yaml, /CreateAfterHookCallbackHdrSqs:/);
589
+ assert.match(yaml, /CreateAfterHookCallback_HdrSqs\.main/);
590
+ });
591
+
592
+ test('emits async before-hook callback and SNS publish in Create_Main and flow-objects.yml', async () => {
593
+ const rootPath = await createProject(true);
594
+ const schemas = join(rootPath, 'app/src/schemas');
595
+ await writeFile(
596
+ join(schemas, 'FlowSchemas/ValidateBeforeCreate.js'),
597
+ "export default { flowTag: 'validateBeforeCreate', event: ['ownTopic'], generatedCodeConfig: { generateCodeTag: 'create', codeHookTag: 'before', invocationType: 'ownTopic' }, objType: { objectType: 'order' } };\n"
598
+ );
599
+ await generateCrudApplicationArtifacts(rootPath, {
600
+ serviceTag: 'orders'
601
+ });
602
+
603
+ const createMain = await readFile(
604
+ join(
605
+ rootPath,
606
+ 'app/src/generatedCode/FlowObjects/Create/source/Create_Main.js'
607
+ ),
608
+ 'utf8'
609
+ );
610
+ assert.match(createMain, /sns\.publishAsync\(_izContext,/);
611
+ assert.match(
612
+ createMain,
613
+ /snsTopicArnByFlowSchema\(\s*_izContext,\s*'validateBeforeCreate_In'\s*\)/
614
+ );
615
+ assert.match(createMain, /CreateBeforeHookCallbackHdrSqs/);
616
+
617
+ const beforeHookMain = await readFile(
618
+ join(
619
+ rootPath,
620
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateBeforeHookCallback_Main.js'
621
+ ),
622
+ 'utf8'
623
+ );
624
+ assert.match(
625
+ beforeHookMain,
626
+ /export default async function CreateBeforeHookCallbackMain/
627
+ );
628
+ assert.match(beforeHookMain, /CreateLogicalLib/);
629
+
630
+ const beforeHookHdrSqs = await readFile(
631
+ join(
632
+ rootPath,
633
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateBeforeHookCallback_HdrSqs.js'
634
+ ),
635
+ 'utf8'
636
+ );
637
+ assert.match(beforeHookHdrSqs, /CreateBeforeHookCallbackMain/);
638
+
639
+ execFileSync(
640
+ process.execPath,
641
+ [
642
+ '--check',
643
+ join(
644
+ rootPath,
645
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateBeforeHookCallback_Main.js'
646
+ )
647
+ ],
648
+ { stdio: 'inherit' }
649
+ );
650
+ execFileSync(
651
+ process.execPath,
652
+ [
653
+ '--check',
654
+ join(
655
+ rootPath,
656
+ 'app/src/generatedCode/FlowObjects/Create/source/CreateBeforeHookCallback_HdrSqs.js'
657
+ )
658
+ ],
659
+ { stdio: 'inherit' }
660
+ );
661
+ execFileSync(
662
+ process.execPath,
663
+ [
664
+ '--check',
665
+ join(
666
+ rootPath,
667
+ 'app/src/generatedCode/FlowObjects/Create/source/Create_Main.js'
668
+ )
669
+ ],
670
+ { stdio: 'inherit' }
671
+ );
672
+ });
673
+
674
+ test('emits sync before-hook in Create_Main with abort check', async () => {
675
+ const rootPath = await createProject(true);
676
+ const schemas = join(rootPath, 'app/src/schemas');
677
+ await writeFile(
678
+ join(schemas, 'FlowSchemas/ValidateBeforeCreateSync.js'),
679
+ "export default { flowTag: 'validateBeforeCreateSync', event: ['lambdaSyncInv'], generatedCodeConfig: { generateCodeTag: 'create', codeHookTag: 'before', invocationType: 'lambdaSyncInv' }, objType: { objectType: 'order' } };\n"
680
+ );
681
+ await generateCrudApplicationArtifacts(rootPath, {
682
+ serviceTag: 'orders'
683
+ });
684
+
685
+ const createMain = await readFile(
686
+ join(
687
+ rootPath,
688
+ 'app/src/generatedCode/FlowObjects/Create/source/Create_Main.js'
689
+ ),
690
+ 'utf8'
691
+ );
692
+ assert.match(
693
+ createMain,
694
+ /lambda\.invokeSync\(\s*_izContext,\s*await lambdaSharedLib\.lambdaFunctionName\(\s*_izContext,\s*'validateBeforeCreateSync'\s*\)/
695
+ );
696
+ assert.match(createMain, /Hook validateBeforeCreateSync failed/);
697
+
698
+ execFileSync(
699
+ process.execPath,
700
+ [
701
+ '--check',
702
+ join(
703
+ rootPath,
704
+ 'app/src/generatedCode/FlowObjects/Create/source/Create_Main.js'
705
+ )
706
+ ],
707
+ { stdio: 'inherit' }
708
+ );
709
+ });
710
+
711
+ test('emits async before-hook callback and SNS publish in Update_Main and flow-objects.yml', async () => {
712
+ const rootPath = await createProject(true);
713
+ const schemas = join(rootPath, 'app/src/schemas');
714
+ await writeFile(
715
+ join(schemas, 'FlowSchemas/ValidateBeforeUpdate.js'),
716
+ "export default { flowTag: 'validateBeforeUpdate', event: ['ownTopic'], generatedCodeConfig: { generateCodeTag: 'update', codeHookTag: 'before', invocationType: 'ownTopic' }, objType: { objectType: 'order' } };\n"
717
+ );
718
+ await generateCrudApplicationArtifacts(rootPath, {
719
+ serviceTag: 'orders'
720
+ });
721
+
722
+ const updateMain = await readFile(
723
+ join(
724
+ rootPath,
725
+ 'app/src/generatedCode/FlowObjects/Update/source/Update_Main.js'
726
+ ),
727
+ 'utf8'
728
+ );
729
+ assert.match(updateMain, /sns\.publishAsync\(_izContext,/);
730
+ assert.match(
731
+ updateMain,
732
+ /snsTopicArnByFlowSchema\(\s*_izContext,\s*'validateBeforeUpdate_In'\s*\)/
733
+ );
734
+ assert.match(updateMain, /UpdateBeforeHookCallbackHdrSqs/);
735
+
736
+ const beforeHookMain = await readFile(
737
+ join(
738
+ rootPath,
739
+ 'app/src/generatedCode/FlowObjects/Update/source/UpdateBeforeHookCallback_Main.js'
740
+ ),
741
+ 'utf8'
742
+ );
743
+ assert.match(
744
+ beforeHookMain,
745
+ /export default async function UpdateBeforeHookCallbackMain/
746
+ );
747
+ assert.match(beforeHookMain, /UpdateLogicalLib/);
748
+ assert.match(beforeHookMain, /handleUpdateError/);
749
+
750
+ const beforeHookHdrSqs = await readFile(
751
+ join(
752
+ rootPath,
753
+ 'app/src/generatedCode/FlowObjects/Update/source/UpdateBeforeHookCallback_HdrSqs.js'
754
+ ),
755
+ 'utf8'
756
+ );
757
+ assert.match(beforeHookHdrSqs, /UpdateBeforeHookCallbackMain/);
758
+
759
+ execFileSync(
760
+ process.execPath,
761
+ [
762
+ '--check',
763
+ join(
764
+ rootPath,
765
+ 'app/src/generatedCode/FlowObjects/Update/source/UpdateBeforeHookCallback_Main.js'
766
+ )
767
+ ],
768
+ { stdio: 'inherit' }
769
+ );
770
+ execFileSync(
771
+ process.execPath,
772
+ [
773
+ '--check',
774
+ join(
775
+ rootPath,
776
+ 'app/src/generatedCode/FlowObjects/Update/source/UpdateBeforeHookCallback_HdrSqs.js'
777
+ )
778
+ ],
779
+ { stdio: 'inherit' }
780
+ );
781
+ execFileSync(
782
+ process.execPath,
783
+ [
784
+ '--check',
785
+ join(
786
+ rootPath,
787
+ 'app/src/generatedCode/FlowObjects/Update/source/Update_Main.js'
788
+ )
789
+ ],
790
+ { stdio: 'inherit' }
791
+ );
792
+ });
793
+
794
+ test('emits sync before-hook in Update_Main with abort check', async () => {
795
+ const rootPath = await createProject(true);
796
+ const schemas = join(rootPath, 'app/src/schemas');
797
+ await writeFile(
798
+ join(schemas, 'FlowSchemas/ValidateBeforeUpdateSync.js'),
799
+ "export default { flowTag: 'validateBeforeUpdateSync', event: ['lambdaSyncInv'], generatedCodeConfig: { generateCodeTag: 'update', codeHookTag: 'before', invocationType: 'lambdaSyncInv' }, objType: { objectType: 'order' } };\n"
800
+ );
801
+ await generateCrudApplicationArtifacts(rootPath, {
802
+ serviceTag: 'orders'
803
+ });
804
+
805
+ const updateMain = await readFile(
806
+ join(
807
+ rootPath,
808
+ 'app/src/generatedCode/FlowObjects/Update/source/Update_Main.js'
809
+ ),
810
+ 'utf8'
811
+ );
812
+ assert.match(
813
+ updateMain,
814
+ /lambda\.invokeSync\(\s*_izContext,\s*await lambdaSharedLib\.lambdaFunctionName\(\s*_izContext,\s*'validateBeforeUpdateSync'\s*\)/
815
+ );
816
+ assert.match(updateMain, /Hook validateBeforeUpdateSync failed/);
817
+
818
+ execFileSync(
819
+ process.execPath,
820
+ [
821
+ '--check',
822
+ join(
823
+ rootPath,
824
+ 'app/src/generatedCode/FlowObjects/Update/source/Update_Main.js'
825
+ )
826
+ ],
827
+ { stdio: 'inherit' }
828
+ );
829
+ });
830
+
831
+ test('emits async before-hook callback and SNS publish in Delete_Main and flow-objects.yml', async () => {
832
+ const rootPath = await createProject(true);
833
+ const schemas = join(rootPath, 'app/src/schemas');
834
+ await writeFile(
835
+ join(schemas, 'FlowSchemas/ValidateBeforeDelete.js'),
836
+ "export default { flowTag: 'validateBeforeDelete', event: ['ownTopic'], generatedCodeConfig: { generateCodeTag: 'delete', codeHookTag: 'before', invocationType: 'ownTopic' }, objType: { objectType: 'order' } };\n"
837
+ );
838
+ await generateCrudApplicationArtifacts(rootPath, {
839
+ serviceTag: 'orders'
840
+ });
841
+
842
+ const deleteMain = await readFile(
843
+ join(
844
+ rootPath,
845
+ 'app/src/generatedCode/FlowObjects/Delete/source/Delete_Main.js'
846
+ ),
847
+ 'utf8'
848
+ );
849
+ assert.match(deleteMain, /sns\.publishAsync\(_izContext,/);
850
+ assert.match(
851
+ deleteMain,
852
+ /snsTopicArnByFlowSchema\(\s*_izContext,\s*'validateBeforeDelete_In'\s*\)/
853
+ );
854
+ assert.match(deleteMain, /DeleteBeforeHookCallbackHdrSqs/);
855
+
856
+ const beforeHookMain = await readFile(
857
+ join(
858
+ rootPath,
859
+ 'app/src/generatedCode/FlowObjects/Delete/source/DeleteBeforeHookCallback_Main.js'
860
+ ),
861
+ 'utf8'
862
+ );
863
+ assert.match(
864
+ beforeHookMain,
865
+ /export default async function DeleteBeforeHookCallbackMain/
866
+ );
867
+ assert.match(beforeHookMain, /DeleteLogicalLib/);
868
+ assert.match(beforeHookMain, /handleDeleteError/);
869
+
870
+ const beforeHookHdrSqs = await readFile(
871
+ join(
872
+ rootPath,
873
+ 'app/src/generatedCode/FlowObjects/Delete/source/DeleteBeforeHookCallback_HdrSqs.js'
874
+ ),
875
+ 'utf8'
876
+ );
877
+ assert.match(beforeHookHdrSqs, /DeleteBeforeHookCallbackMain/);
878
+
879
+ execFileSync(
880
+ process.execPath,
881
+ [
882
+ '--check',
883
+ join(
884
+ rootPath,
885
+ 'app/src/generatedCode/FlowObjects/Delete/source/DeleteBeforeHookCallback_Main.js'
886
+ )
887
+ ],
888
+ { stdio: 'inherit' }
889
+ );
890
+ execFileSync(
891
+ process.execPath,
892
+ [
893
+ '--check',
894
+ join(
895
+ rootPath,
896
+ 'app/src/generatedCode/FlowObjects/Delete/source/DeleteBeforeHookCallback_HdrSqs.js'
897
+ )
898
+ ],
899
+ { stdio: 'inherit' }
900
+ );
901
+ execFileSync(
902
+ process.execPath,
903
+ [
904
+ '--check',
905
+ join(
906
+ rootPath,
907
+ 'app/src/generatedCode/FlowObjects/Delete/source/Delete_Main.js'
908
+ )
909
+ ],
910
+ { stdio: 'inherit' }
911
+ );
912
+ });
913
+
914
+ test('emits sync before-hook in Delete_Main with abort check', async () => {
915
+ const rootPath = await createProject(true);
916
+ const schemas = join(rootPath, 'app/src/schemas');
917
+ await writeFile(
918
+ join(schemas, 'FlowSchemas/ValidateBeforeDeleteSync.js'),
919
+ "export default { flowTag: 'validateBeforeDeleteSync', event: ['lambdaSyncInv'], generatedCodeConfig: { generateCodeTag: 'delete', codeHookTag: 'before', invocationType: 'lambdaSyncInv' }, objType: { objectType: 'order' } };\n"
920
+ );
921
+ await generateCrudApplicationArtifacts(rootPath, {
922
+ serviceTag: 'orders'
923
+ });
924
+
925
+ const deleteMain = await readFile(
926
+ join(
927
+ rootPath,
928
+ 'app/src/generatedCode/FlowObjects/Delete/source/Delete_Main.js'
929
+ ),
930
+ 'utf8'
931
+ );
932
+ assert.match(
933
+ deleteMain,
934
+ /lambda\.invokeSync\(\s*_izContext,\s*await lambdaSharedLib\.lambdaFunctionName\(\s*_izContext,\s*'validateBeforeDeleteSync'\s*\)/
935
+ );
936
+ assert.match(deleteMain, /Hook validateBeforeDeleteSync failed/);
937
+
938
+ execFileSync(
939
+ process.execPath,
940
+ [
941
+ '--check',
942
+ join(
943
+ rootPath,
944
+ 'app/src/generatedCode/FlowObjects/Delete/source/Delete_Main.js'
945
+ )
946
+ ],
947
+ { stdio: 'inherit' }
948
+ );
949
+ });
950
+
420
951
  async function createProject(withCrudObject) {
421
952
  const rootPath = await mkdtemp(
422
953
  join(tmpdir(), 'generate-service-code-v2-crud-application-')