@smartive/graphql-magic 19.1.3-next.2 → 19.2.0-next.2

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- ## [19.1.3-next.2](https://github.com/smartive/graphql-magic/compare/v19.1.3-next.1...v19.1.3-next.2) (2025-06-11)
1
+ # [19.2.0-next.2](https://github.com/smartive/graphql-magic/compare/v19.2.0-next.1...v19.2.0-next.2) (2025-06-18)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * Heuristics ([2193bf7](https://github.com/smartive/graphql-magic/commit/2193bf7eb53d5d24babc60c98b26f843e28d27b8))
6
+ * Trigger ([764fa98](https://github.com/smartive/graphql-magic/commit/764fa98e3e801a9d13e37b71f5bd43994456f6e9))
package/dist/bin/gqm.cjs CHANGED
@@ -571,6 +571,7 @@ var get = (object2, key) => {
571
571
  if (value2 === void 0 || value2 === null) {
572
572
  const error = new Error(`Object doesn't have ${String(key)}`);
573
573
  console.warn(error);
574
+ console.trace();
574
575
  throw error;
575
576
  }
576
577
  return value2;
@@ -67,7 +67,10 @@ __export(index_exports, {
67
67
  args: () => args,
68
68
  as: () => as,
69
69
  checkCanWrite: () => checkCanWrite,
70
+ createEntity: () => createEntity,
70
71
  createRevision: () => createRevision,
72
+ deleteEntities: () => deleteEntities,
73
+ deleteEntity: () => deleteEntity,
71
74
  directive: () => directive,
72
75
  directives: () => directives,
73
76
  displayField: () => displayField,
@@ -176,12 +179,15 @@ __export(index_exports, {
176
179
  queryRelations: () => queryRelations,
177
180
  queryResolver: () => queryResolver,
178
181
  resolve: () => resolve,
182
+ restoreEntity: () => restoreEntity,
179
183
  retry: () => retry,
180
184
  scalar: () => scalar,
181
185
  summon: () => summon,
182
186
  summonByKey: () => summonByKey,
183
187
  summonByName: () => summonByName,
184
188
  typeToField: () => typeToField,
189
+ updateEntities: () => updateEntities,
190
+ updateEntity: () => updateEntity,
185
191
  value: () => value
186
192
  });
187
193
  module.exports = __toCommonJS(index_exports);
@@ -789,6 +795,7 @@ var get = (object2, key) => {
789
795
  if (value2 === void 0 || value2 === null) {
790
796
  const error = new Error(`Object doesn't have ${String(key)}`);
791
797
  console.warn(error);
798
+ console.trace();
792
799
  throw error;
793
800
  }
794
801
  return value2;
@@ -2665,22 +2672,40 @@ var mutationResolver = async (_parent, args2, partialCtx, info) => {
2665
2672
  const ctx = { ...partialCtx, knex, info, aliases: new AliasGenerator() };
2666
2673
  const model = ctx.models.getModel(modelName, "entity");
2667
2674
  switch (mutation) {
2668
- case "create":
2669
- return await create(model, args2, ctx);
2670
- case "update":
2671
- return await update(model, args2, ctx);
2672
- case "delete":
2673
- return await del(model, args2, ctx);
2674
- case "restore":
2675
- return await restore(model, args2, ctx);
2675
+ case "create": {
2676
+ const id = await createEntity(model, args2.data, ctx, "mutation");
2677
+ return await resolve(ctx, id);
2678
+ }
2679
+ case "update": {
2680
+ const id = args2.where.id;
2681
+ await updateEntity(model, id, args2.data, ctx);
2682
+ return await resolve(ctx, id);
2683
+ }
2684
+ case "delete": {
2685
+ const id = args2.where.id;
2686
+ await deleteEntity(model, id, args2.dryRun, model.rootModel.name, id, ctx, "mutation");
2687
+ return id;
2688
+ }
2689
+ case "restore": {
2690
+ const id = args2.where.id;
2691
+ await restoreEntity(model, id, ctx, "mutation");
2692
+ return id;
2693
+ }
2676
2694
  }
2677
2695
  });
2678
2696
  };
2679
- var create = async (model, { data: input2 }, ctx) => {
2697
+ var createEntity = async (model, input2, ctx, trigger = "direct-call") => {
2680
2698
  const normalizedInput = { ...input2 };
2681
- normalizedInput.id = (0, import_uuid.v4)();
2682
- normalizedInput.createdAt = ctx.now;
2683
- normalizedInput.createdById = ctx.user?.id;
2699
+ if (!normalizedInput.id) {
2700
+ normalizedInput.id = (0, import_uuid.v4)();
2701
+ }
2702
+ const id = normalizedInput.id;
2703
+ if (!normalizedInput.createdAt) {
2704
+ normalizedInput.createdAt = ctx.now;
2705
+ }
2706
+ if (!normalizedInput.createdById) {
2707
+ normalizedInput.createdById = ctx.user?.id;
2708
+ }
2684
2709
  if (model.parent) {
2685
2710
  normalizedInput.type = model.name;
2686
2711
  }
@@ -2688,10 +2713,10 @@ var create = async (model, { data: input2 }, ctx) => {
2688
2713
  await checkCanWrite(ctx, model, normalizedInput, "CREATE");
2689
2714
  await ctx.handleUploads?.(normalizedInput);
2690
2715
  const data = { prev: {}, input: input2, normalizedInput, next: normalizedInput };
2691
- await ctx.mutationHook?.({ model, action: "create", trigger: "mutation", when: "before", data, ctx });
2716
+ await ctx.mutationHook?.({ model, action: "create", trigger, when: "before", data, ctx });
2692
2717
  if (model.parent) {
2693
2718
  const rootInput = {};
2694
- const childInput = { id: normalizedInput.id };
2719
+ const childInput = { id };
2695
2720
  for (const field of model.fields) {
2696
2721
  const columnName = field.kind === "relation" ? `${field.name}Id` : field.name;
2697
2722
  if (columnName in normalizedInput) {
@@ -2708,60 +2733,55 @@ var create = async (model, { data: input2 }, ctx) => {
2708
2733
  await ctx.knex(model.name).insert(normalizedInput);
2709
2734
  }
2710
2735
  await createRevision(model, normalizedInput, ctx);
2711
- await ctx.mutationHook?.({ model, action: "create", trigger: "mutation", when: "after", data, ctx });
2712
- return await resolve(ctx, normalizedInput.id);
2736
+ await ctx.mutationHook?.({ model, action: "create", trigger, when: "after", data, ctx });
2737
+ return normalizedInput.id;
2713
2738
  };
2714
- var update = async (model, { where, data: input2 }, ctx) => {
2715
- if (Object.keys(where).length === 0) {
2716
- throw new Error(`No ${model.name} specified.`);
2739
+ var updateEntities = async (model, where, updateFields, ctx) => {
2740
+ const entities = await ctx.knex(model.name).where(where).select("id");
2741
+ for (const entity of entities) {
2742
+ await updateEntity(model, entity.id, updateFields, ctx);
2717
2743
  }
2744
+ };
2745
+ var updateEntity = async (model, id, input2, ctx, trigger = "direct-call") => {
2718
2746
  const normalizedInput = { ...input2 };
2719
2747
  sanitize(ctx, model, normalizedInput);
2720
- const prev = await getEntityToMutate(ctx, model, where, "UPDATE");
2748
+ const currentEntity = await getEntityToMutate(ctx, model, { id }, "UPDATE");
2721
2749
  for (const key of Object.keys(normalizedInput)) {
2722
- if (normalizedInput[key] === prev[key]) {
2750
+ if (normalizedInput[key] === currentEntity[key]) {
2723
2751
  delete normalizedInput[key];
2724
2752
  }
2725
2753
  }
2726
2754
  if (Object.keys(normalizedInput).length > 0) {
2727
2755
  await checkCanWrite(ctx, model, normalizedInput, "UPDATE");
2728
2756
  await ctx.handleUploads?.(normalizedInput);
2729
- const next = { ...prev, ...normalizedInput };
2730
- const data = { prev, input: input2, normalizedInput, next };
2731
- await ctx.mutationHook?.({ model, action: "update", trigger: "mutation", when: "before", data, ctx });
2732
- if (model.parent) {
2733
- const rootInput = {};
2734
- const childInput = {};
2735
- for (const field of model.fields) {
2736
- const columnName = field.kind === "relation" ? `${field.name}Id` : field.name;
2737
- if (columnName in normalizedInput) {
2738
- if (field.inherited) {
2739
- rootInput[columnName] = normalizedInput[columnName];
2740
- } else {
2741
- childInput[columnName] = normalizedInput[columnName];
2742
- }
2743
- }
2744
- }
2745
- if (Object.keys(rootInput).length) {
2746
- await ctx.knex(model.parent).where({ id: prev.id }).update(rootInput);
2747
- }
2748
- if (Object.keys(childInput).length) {
2749
- await ctx.knex(model.name).where({ id: prev.id }).update(childInput);
2750
- }
2751
- } else {
2752
- await ctx.knex(model.name).where({ id: prev.id }).update(normalizedInput);
2753
- }
2754
- await createRevision(model, next, ctx);
2755
- await ctx.mutationHook?.({ model, action: "update", trigger: "mutation", when: "after", data, ctx });
2757
+ await ctx.mutationHook?.({
2758
+ model,
2759
+ action: "update",
2760
+ trigger,
2761
+ when: "before",
2762
+ data: { prev: currentEntity, input: input2, normalizedInput, next: { ...currentEntity, ...normalizedInput } },
2763
+ ctx
2764
+ });
2765
+ await doUpdate(model, currentEntity, normalizedInput, ctx);
2766
+ await ctx.mutationHook?.({
2767
+ model,
2768
+ action: "update",
2769
+ trigger,
2770
+ when: "after",
2771
+ data: { prev: currentEntity, input: input2, normalizedInput, next: { ...currentEntity, ...normalizedInput } },
2772
+ ctx
2773
+ });
2756
2774
  }
2757
- return await resolve(ctx);
2758
2775
  };
2759
- var del = async (model, { where, dryRun }, ctx) => {
2760
- if (Object.keys(where).length === 0) {
2761
- throw new Error(`No ${model.name} specified.`);
2776
+ var deleteEntities = async (model, where, deleteRootType, deleteRootId, ctx) => {
2777
+ const entities = await ctx.knex(model.name).where(where).select("id");
2778
+ for (const entity of entities) {
2779
+ await deleteEntity(model, entity.id, false, deleteRootType, deleteRootId, ctx);
2762
2780
  }
2781
+ };
2782
+ var deleteEntity = async (model, id, dryRun, deleteRootType = model.rootModel.name, deleteRootId = id, ctx, trigger = "direct-call") => {
2763
2783
  const rootModel = model.rootModel;
2764
- const entity = await getEntityToMutate(ctx, rootModel, where, "DELETE");
2784
+ const entity = await getEntityToMutate(ctx, rootModel, { id }, "DELETE");
2765
2785
  if (entity.deleted) {
2766
2786
  throw new ForbiddenError(`${getTechnicalDisplay(model, entity)} is already deleted.`);
2767
2787
  }
@@ -2772,7 +2792,7 @@ var del = async (model, { where, dryRun }, ctx) => {
2772
2792
  const mutations = [];
2773
2793
  const afterHooks = [];
2774
2794
  const mutationHook = ctx.mutationHook;
2775
- const deleteCascade = async (currentModel, currentEntity) => {
2795
+ const deleteCascade = async (currentModel, currentEntity, currentTrigger) => {
2776
2796
  if (!(currentModel.name in toDelete)) {
2777
2797
  toDelete[currentModel.name] = {};
2778
2798
  }
@@ -2780,41 +2800,37 @@ var del = async (model, { where, dryRun }, ctx) => {
2780
2800
  return;
2781
2801
  }
2782
2802
  toDelete[currentModel.name][currentEntity.id] = await fetchDisplay(ctx.knex, currentModel, currentEntity);
2783
- const trigger = currentModel.name === rootModel.name && currentEntity.id === entity.id ? "mutation" : "cascade";
2784
2803
  if (!dryRun) {
2785
2804
  const normalizedInput = {
2786
2805
  deleted: true,
2787
2806
  deletedAt: ctx.now,
2788
2807
  deletedById: ctx.user?.id,
2789
- deleteRootType: rootModel.name,
2790
- deleteRootId: entity.id
2808
+ deleteRootType,
2809
+ deleteRootId
2791
2810
  };
2792
- const next = { ...currentEntity, ...normalizedInput };
2793
- const data = { prev: currentEntity, input: {}, normalizedInput, next };
2794
2811
  if (mutationHook) {
2795
2812
  beforeHooks.push(async () => {
2796
2813
  await mutationHook({
2797
2814
  model: currentModel,
2798
2815
  action: "delete",
2799
- trigger,
2816
+ trigger: currentTrigger,
2800
2817
  when: "before",
2801
- data,
2818
+ data: { prev: currentEntity, input: {}, normalizedInput, next: { ...currentEntity, ...normalizedInput } },
2802
2819
  ctx
2803
2820
  });
2804
2821
  });
2805
2822
  }
2806
2823
  mutations.push(async () => {
2807
- await ctx.knex(currentModel.name).where({ id: currentEntity.id }).update(normalizedInput);
2808
- await createRevision(currentModel, next, ctx);
2824
+ await doUpdate(currentModel, currentEntity, normalizedInput, ctx);
2809
2825
  });
2810
2826
  if (mutationHook) {
2811
2827
  afterHooks.push(async () => {
2812
2828
  await mutationHook({
2813
2829
  model: currentModel,
2814
2830
  action: "delete",
2815
- trigger,
2831
+ trigger: currentTrigger,
2816
2832
  when: "after",
2817
- data,
2833
+ data: { prev: currentEntity, input: {}, normalizedInput, next: { ...currentEntity, ...normalizedInput } },
2818
2834
  ctx
2819
2835
  });
2820
2836
  });
@@ -2843,8 +2859,6 @@ var del = async (model, { where, dryRun }, ctx) => {
2843
2859
  toUnlink[descendantModel.name][descendant.id].fields.push(name2);
2844
2860
  } else {
2845
2861
  const normalizedInput = { [`${name2}Id`]: null };
2846
- const next = { ...descendant, ...normalizedInput };
2847
- const data = { prev: descendant, input: {}, normalizedInput, next };
2848
2862
  if (mutationHook) {
2849
2863
  beforeHooks.push(async () => {
2850
2864
  await mutationHook({
@@ -2852,14 +2866,13 @@ var del = async (model, { where, dryRun }, ctx) => {
2852
2866
  action: "update",
2853
2867
  trigger: "set-null",
2854
2868
  when: "before",
2855
- data,
2869
+ data: { prev: descendant, input: {}, normalizedInput, next: { ...descendant, ...normalizedInput } },
2856
2870
  ctx
2857
2871
  });
2858
2872
  });
2859
2873
  }
2860
2874
  mutations.push(async () => {
2861
- await ctx.knex(descendantModel.name).where({ id: descendant.id }).update(normalizedInput);
2862
- await createRevision(descendantModel, next, ctx);
2875
+ await doUpdate(descendantModel, descendant, normalizedInput, ctx);
2863
2876
  });
2864
2877
  if (mutationHook) {
2865
2878
  afterHooks.push(async () => {
@@ -2868,7 +2881,7 @@ var del = async (model, { where, dryRun }, ctx) => {
2868
2881
  action: "update",
2869
2882
  trigger: "set-null",
2870
2883
  when: "after",
2871
- data,
2884
+ data: { prev: descendant, input: {}, normalizedInput, next: { ...descendant, ...normalizedInput } },
2872
2885
  ctx
2873
2886
  });
2874
2887
  });
@@ -2914,7 +2927,7 @@ var del = async (model, { where, dryRun }, ctx) => {
2914
2927
  );
2915
2928
  }
2916
2929
  for (const descendant of descendants) {
2917
- await deleteCascade(descendantModel, descendant);
2930
+ await deleteCascade(descendantModel, descendant, "cascade");
2918
2931
  }
2919
2932
  break;
2920
2933
  }
@@ -2922,7 +2935,7 @@ var del = async (model, { where, dryRun }, ctx) => {
2922
2935
  }
2923
2936
  }
2924
2937
  };
2925
- await deleteCascade(rootModel, entity);
2938
+ await deleteCascade(rootModel, entity, trigger);
2926
2939
  for (const callback of [...beforeHooks, ...mutations, ...afterHooks]) {
2927
2940
  await callback();
2928
2941
  }
@@ -2934,14 +2947,10 @@ var del = async (model, { where, dryRun }, ctx) => {
2934
2947
  restricted
2935
2948
  });
2936
2949
  }
2937
- return entity.id;
2938
2950
  };
2939
- var restore = async (model, { where }, ctx) => {
2940
- if (Object.keys(where).length === 0) {
2941
- throw new Error(`No ${model.name} specified.`);
2942
- }
2951
+ var restoreEntity = async (model, id, ctx, trigger = "direct-call") => {
2943
2952
  const rootModel = model.rootModel;
2944
- const entity = await getEntityToMutate(ctx, rootModel, where, "RESTORE");
2953
+ const entity = await getEntityToMutate(ctx, rootModel, { id }, "RESTORE");
2945
2954
  if (!entity.deleted) {
2946
2955
  throw new ForbiddenError(`${getTechnicalDisplay(model, entity)} is not deleted.`);
2947
2956
  }
@@ -2956,9 +2965,9 @@ var restore = async (model, { where }, ctx) => {
2956
2965
  const beforeHooks = [];
2957
2966
  const mutations = [];
2958
2967
  const afterHooks = [];
2959
- const restoreCascade = async (currentModel, currentEntity) => {
2968
+ const restoreCascade = async (currentModel, currentEntity, currentTrigger) => {
2960
2969
  if (entity.deleteRootId) {
2961
- if (!(currentEntity.deleteRootType === currentModel.name && currentEntity.deleteRootId === entity.id)) {
2970
+ if (!(currentEntity.deleteRootType === model.name && currentEntity.deleteRootId === entity.id)) {
2962
2971
  return;
2963
2972
  }
2964
2973
  } else if (!anyDateToLuxon(currentEntity.deletedAt, ctx.timeZone).equals(anyDateToLuxon(entity.deletedAt, ctx.timeZone))) {
@@ -2969,7 +2978,7 @@ var restore = async (model, { where }, ctx) => {
2969
2978
  }
2970
2979
  toRestore[currentModel.name].add(currentEntity.id);
2971
2980
  for (const relation of currentModel.relations) {
2972
- const parentId = entity[relation.field.foreignKey];
2981
+ const parentId = currentEntity[relation.field.foreignKey];
2973
2982
  if (!parentId) {
2974
2983
  continue;
2975
2984
  }
@@ -2993,16 +3002,29 @@ var restore = async (model, { where }, ctx) => {
2993
3002
  const data = { prev: currentEntity, input: {}, normalizedInput, next: { ...currentEntity, ...normalizedInput } };
2994
3003
  if (ctx.mutationHook) {
2995
3004
  beforeHooks.push(async () => {
2996
- await ctx.mutationHook({ model: currentModel, action: "restore", trigger: "mutation", when: "before", data, ctx });
3005
+ await ctx.mutationHook({
3006
+ model: currentModel,
3007
+ action: "restore",
3008
+ trigger: currentTrigger,
3009
+ when: "before",
3010
+ data,
3011
+ ctx
3012
+ });
2997
3013
  });
2998
3014
  }
2999
3015
  mutations.push(async () => {
3000
- await ctx.knex(currentModel.name).where({ id: currentEntity.id }).update(normalizedInput);
3001
- await createRevision(currentModel, { ...currentEntity, deleted: false }, ctx);
3016
+ await doUpdate(currentModel, currentEntity, normalizedInput, ctx);
3002
3017
  });
3003
3018
  if (ctx.mutationHook) {
3004
3019
  afterHooks.push(async () => {
3005
- await ctx.mutationHook({ model: currentModel, action: "restore", trigger: "mutation", when: "after", data, ctx });
3020
+ await ctx.mutationHook({
3021
+ model: currentModel,
3022
+ action: "restore",
3023
+ trigger: currentTrigger,
3024
+ when: "after",
3025
+ data,
3026
+ ctx
3027
+ });
3006
3028
  });
3007
3029
  }
3008
3030
  for (const {
@@ -3022,15 +3044,14 @@ var restore = async (model, { where }, ctx) => {
3022
3044
  );
3023
3045
  }
3024
3046
  for (const descendant of deletedDescendants) {
3025
- await restoreCascade(descendantModel, descendant);
3047
+ await restoreCascade(descendantModel, descendant, "cascade");
3026
3048
  }
3027
3049
  }
3028
3050
  };
3029
- await restoreCascade(rootModel, entity);
3051
+ await restoreCascade(rootModel, entity, trigger);
3030
3052
  for (const callback of [...beforeHooks, ...mutations, ...afterHooks]) {
3031
3053
  await callback();
3032
3054
  }
3033
- return entity.id;
3034
3055
  };
3035
3056
  var createRevision = async (model, data, ctx) => {
3036
3057
  if (model.updatable) {
@@ -3069,8 +3090,12 @@ var createRevision = async (model, data, ctx) => {
3069
3090
  };
3070
3091
  var sanitize = (ctx, model, data) => {
3071
3092
  if (model.updatable) {
3072
- data.updatedAt = ctx.now;
3073
- data.updatedById = ctx.user?.id;
3093
+ if (!data.updatedAt) {
3094
+ data.updatedAt = ctx.now;
3095
+ }
3096
+ if (!data.updatedById) {
3097
+ data.updatedById = ctx.user?.id;
3098
+ }
3074
3099
  }
3075
3100
  for (const key of Object.keys(data)) {
3076
3101
  const field = model.fields.find(({ name: name2 }) => name2 === key);
@@ -3093,6 +3118,39 @@ var sanitize = (ctx, model, data) => {
3093
3118
  };
3094
3119
  var isEndOfDay = (field) => isPrimitive(field) && field.type === "DateTime" && field?.endOfDay === true && field?.dateTimeType === "date";
3095
3120
  var isEndOfMonth = (field) => isPrimitive(field) && field.type === "DateTime" && field?.endOfMonth === true && field?.dateTimeType === "year_and_month";
3121
+ var doUpdate = async (model, currentEntity, update, ctx) => {
3122
+ if (model.updatable) {
3123
+ if (!update.updatedAt) {
3124
+ update.updatedAt = ctx.now;
3125
+ }
3126
+ if (!update.updatedById) {
3127
+ update.updatedById = ctx.user?.id;
3128
+ }
3129
+ }
3130
+ if (model.parent) {
3131
+ const rootInput = {};
3132
+ const childInput = {};
3133
+ for (const field of model.fields) {
3134
+ const columnName = field.kind === "relation" ? `${field.name}Id` : field.name;
3135
+ if (columnName in update) {
3136
+ if (field.inherited) {
3137
+ rootInput[columnName] = update[columnName];
3138
+ } else {
3139
+ childInput[columnName] = update[columnName];
3140
+ }
3141
+ }
3142
+ }
3143
+ if (Object.keys(rootInput).length) {
3144
+ await ctx.knex(model.parent).where({ id: currentEntity.id }).update(rootInput);
3145
+ }
3146
+ if (Object.keys(childInput).length) {
3147
+ await ctx.knex(model.name).where({ id: currentEntity.id }).update(childInput);
3148
+ }
3149
+ } else {
3150
+ await ctx.knex(model.name).where({ id: currentEntity.id }).update(update);
3151
+ }
3152
+ await createRevision(model, { ...currentEntity, ...update }, ctx);
3153
+ };
3096
3154
 
3097
3155
  // src/resolvers/resolvers.ts
3098
3156
  var getResolvers = (models) => {
@@ -3587,7 +3645,10 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql6.buildAST
3587
3645
  args,
3588
3646
  as,
3589
3647
  checkCanWrite,
3648
+ createEntity,
3590
3649
  createRevision,
3650
+ deleteEntities,
3651
+ deleteEntity,
3591
3652
  directive,
3592
3653
  directives,
3593
3654
  displayField,
@@ -3696,11 +3757,14 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql6.buildAST
3696
3757
  queryRelations,
3697
3758
  queryResolver,
3698
3759
  resolve,
3760
+ restoreEntity,
3699
3761
  retry,
3700
3762
  scalar,
3701
3763
  summon,
3702
3764
  summonByKey,
3703
3765
  summonByName,
3704
3766
  typeToField,
3767
+ updateEntities,
3768
+ updateEntity,
3705
3769
  value
3706
3770
  });
@@ -2,10 +2,12 @@ import { AnyDateType, Context } from '..';
2
2
  import { EntityModel } from './models';
3
3
  export type Entity = Record<string, unknown>;
4
4
  export type Action = 'create' | 'update' | 'delete' | 'restore';
5
+ export type Trigger = 'mutation' | 'direct-call' | 'cascade' | 'set-null';
6
+ export type MutationContext<DateType extends AnyDateType = AnyDateType> = Pick<Context<DateType>, 'knex' | 'now' | 'user' | 'timeZone' | 'mutationHook' | 'handleUploads' | 'models' | 'permissions'>;
5
7
  export type MutationHook<DateType extends AnyDateType = AnyDateType> = (args: {
6
8
  model: EntityModel;
7
9
  action: Action;
8
- trigger: 'mutation' | 'cascade' | 'set-null';
10
+ trigger: Trigger;
9
11
  when: 'before' | 'after';
10
12
  data: {
11
13
  prev: Entity;
@@ -13,5 +15,5 @@ export type MutationHook<DateType extends AnyDateType = AnyDateType> = (args: {
13
15
  normalizedInput: Entity;
14
16
  next: Entity;
15
17
  };
16
- ctx: Context<DateType>;
18
+ ctx: MutationContext<DateType>;
17
19
  }) => Promise<void> | void;
@@ -72,6 +72,7 @@ export const get = (object, key) => {
72
72
  if (value === undefined || value === null) {
73
73
  const error = new Error(`Object doesn't have ${String(key)}`);
74
74
  console.warn(error);
75
+ console.trace();
75
76
  throw error;
76
77
  }
77
78
  return value;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/models/utils.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAGL,WAAW,EAEX,SAAS,EACT,UAAU,EACV,cAAc,EAEd,WAAW,EAEX,YAAY,EAEZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAElB,MAAM,UAAU,GAAG,CAAI,CAA+B,EAAU,EAAE,CAAC,OAAO,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAA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';
2
2
  import { Context } from '../context';
3
3
  import { EntityModel } from '../models/models';
4
- import { Entity } from '../models/mutation-hook';
4
+ import { Entity, MutationContext, Trigger } from '../models/mutation-hook';
5
5
  export declare const mutationResolver: (_parent: any, args: any, partialCtx: Context, info: GraphQLResolveInfo) => Promise<any>;
6
- export declare const createRevision: (model: EntityModel, data: Entity, ctx: Pick<Context, "knex" | "now" | "user">) => Promise<void>;
6
+ export declare const createEntity: (model: EntityModel, input: Entity, ctx: MutationContext, trigger?: Trigger) => Promise<string>;
7
+ export declare const updateEntities: (model: EntityModel, where: Record<string, unknown>, updateFields: Entity, ctx: MutationContext) => Promise<void>;
8
+ export declare const updateEntity: (model: EntityModel, id: string, input: Entity, ctx: MutationContext, trigger?: Trigger) => Promise<void>;
9
+ export declare const deleteEntities: (model: EntityModel, where: Record<string, unknown>, deleteRootType: string | undefined, deleteRootId: string | undefined, ctx: MutationContext) => Promise<void>;
10
+ export declare const deleteEntity: (model: EntityModel, id: string, dryRun: boolean, deleteRootType: string | undefined, deleteRootId: string | undefined, ctx: MutationContext, trigger?: Trigger) => Promise<void>;
11
+ export declare const restoreEntity: (model: EntityModel, id: string, ctx: MutationContext, trigger?: Trigger) => Promise<void>;
12
+ export declare const createRevision: (model: EntityModel, data: Entity, ctx: MutationContext) => Promise<void>;