@snowtop/ent 0.1.2 → 0.1.3

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.
@@ -60,6 +60,21 @@ export interface Action<TEnt extends Ent<TViewer>, TBuilder extends Builder<TEnt
60
60
  changesetWithOptions_BETA?(options: ChangesetOptions): Promise<Changeset>;
61
61
  builder: TBuilder;
62
62
  getPrivacyPolicy(): PrivacyPolicy<TEnt>;
63
+ /**
64
+ * beta API that may change. used to indicate that we should fail privacy errors
65
+ * silently instead of throwing an error
66
+ *
67
+ * valid will still return false
68
+ * validX() will still throw an error
69
+ * save() and saveX() will just fail silently instead of throwing an error
70
+ *
71
+ * NOTE: this doesn't make sense on a create action since we'd still try and load the ent
72
+ * and if it that doesn't exist, we'd throw an error
73
+ *
74
+ * so this is only useful on update or delete actions when there's an existing ent to load
75
+ * or when there isn't any expected return value.
76
+ */
77
+ __failPrivacySilently?(): boolean;
63
78
  getTriggers?(): (Trigger<TEnt, TBuilder, TViewer, TInput, TExistingEnt> | Trigger<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[])[];
64
79
  getObservers?(): Observer<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
65
80
  getValidators?(): Validator<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
@@ -42,6 +42,14 @@ export interface EditNodeOptions<T extends Ent> extends EditRowOptions {
42
42
  onConflict?: CreateRowOptions["onConflict"];
43
43
  builder: Builder<T>;
44
44
  }
45
+ export declare class NoOperation<T extends Ent> implements DataOperation<T> {
46
+ builder: Builder<any>;
47
+ private row;
48
+ constructor(builder: Builder<any>, existingEnt?: Ent | null);
49
+ performWrite(queryer: Queryer, context?: Context): Promise<void>;
50
+ performWriteSync(queryer: SyncQueryer, context?: Context): void;
51
+ returnedRow(): Data | null;
52
+ }
45
53
  export declare class EditNodeOperation<T extends Ent> implements DataOperation {
46
54
  options: EditNodeOptions<T>;
47
55
  private existingEnt;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ConditionalNodeOperation = exports.ConditionalOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.RawQueryOperation = exports.DeleteNodeOperation = void 0;
26
+ exports.ConditionalNodeOperation = exports.ConditionalOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.NoOperation = exports.RawQueryOperation = exports.DeleteNodeOperation = void 0;
27
27
  const clause = __importStar(require("../core/clause"));
28
28
  const action_1 = require("../action");
29
29
  const schema_1 = require("../schema/schema");
@@ -82,6 +82,20 @@ class RawQueryOperation {
82
82
  }
83
83
  }
84
84
  exports.RawQueryOperation = RawQueryOperation;
85
+ class NoOperation {
86
+ constructor(builder, existingEnt = null) {
87
+ this.builder = builder;
88
+ this.row = null;
89
+ // @ts-ignore
90
+ this.row = existingEnt?.data;
91
+ }
92
+ async performWrite(queryer, context) { }
93
+ performWriteSync(queryer, context) { }
94
+ returnedRow() {
95
+ return this.row;
96
+ }
97
+ }
98
+ exports.NoOperation = NoOperation;
85
99
  class EditNodeOperation {
86
100
  constructor(options, existingEnt = null) {
87
101
  this.options = options;
@@ -867,12 +867,29 @@ class Orchestrator {
867
867
  return this.validate();
868
868
  }
869
869
  async buildPlusChangeset(conditionalBuilder, conditionalOverride) {
870
- // validate everything first
871
- await this.validX();
872
- let ops = [
873
- this.buildMainOp(conditionalOverride ? conditionalBuilder : undefined),
874
- ];
875
- await this.buildEdgeOps(ops, conditionalBuilder, conditionalOverride);
870
+ let ops = [];
871
+ let processOps = true;
872
+ if (this.options.action?.__failPrivacySilently &&
873
+ this.options.action.__failPrivacySilently()) {
874
+ const res = await this.valid();
875
+ if (!res) {
876
+ processOps = false;
877
+ const op = new operations_1.NoOperation(this.options.builder, this.existingEnt);
878
+ this.mainOp = op;
879
+ ops = [op];
880
+ // we need an op that just returns the existing ent
881
+ }
882
+ }
883
+ else {
884
+ // validate everything first
885
+ await this.validX();
886
+ }
887
+ if (processOps) {
888
+ ops = [
889
+ this.buildMainOp(conditionalOverride ? conditionalBuilder : undefined),
890
+ ];
891
+ await this.buildEdgeOps(ops, conditionalBuilder, conditionalOverride);
892
+ }
876
893
  // TODO throw if we try and create a new changeset after previously creating one
877
894
  // TODO test actualOperation value
878
895
  // observers is fine since they're run after and we have the actualOperation value...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -98,6 +98,7 @@ export declare class SimpleAction<T extends Ent, TExistingEnt extends TMaybleNul
98
98
  getValidators(): Validator<T, SimpleBuilder<T>>[];
99
99
  getObservers(): Observer<T, SimpleBuilder<T>>[];
100
100
  getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
101
+ __failPrivacySilently(): boolean;
101
102
  getInput(): Data;
102
103
  changeset(): Promise<Changeset>;
103
104
  changesetWithOptions_BETA(options: ChangesetOptions): Promise<Changeset>;
@@ -285,6 +285,9 @@ class SimpleAction {
285
285
  getPrivacyPolicy() {
286
286
  return privacy_1.AlwaysAllowPrivacyPolicy;
287
287
  }
288
+ __failPrivacySilently() {
289
+ return false;
290
+ }
288
291
  getInput() {
289
292
  const ret = {};
290
293
  for (const [k, v] of this.fields) {