@niscorp/tide 0.1.0 → 0.1.1

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/dist/index.d.cts CHANGED
@@ -188,6 +188,10 @@ type GraphReport = {
188
188
  effect: string;
189
189
  }[];
190
190
  errors: readonly string[];
191
+ refusals: readonly {
192
+ code: 'unknown_reflex' | 'unknown_effect' | 'unguarded_cycle';
193
+ message: string;
194
+ }[];
191
195
  warnings: readonly string[];
192
196
  };
193
197
 
package/dist/index.d.ts CHANGED
@@ -188,6 +188,10 @@ type GraphReport = {
188
188
  effect: string;
189
189
  }[];
190
190
  errors: readonly string[];
191
+ refusals: readonly {
192
+ code: 'unknown_reflex' | 'unknown_effect' | 'unguarded_cycle';
193
+ message: string;
194
+ }[];
191
195
  warnings: readonly string[];
192
196
  };
193
197
 
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ var versionOf = (reflex) => {
55
55
  var isGuarded = (reflex) => reflex.select !== void 0 || reflex.when !== void 0;
56
56
  var buildGraph = (reflexes, effects) => {
57
57
  const edges = [];
58
- const errors = [];
58
+ const refusals = [];
59
59
  const warnings = [];
60
60
  const blind = [];
61
61
  const byId = new Map(reflexes.map((reflex) => [reflex.id, reflex]));
@@ -71,13 +71,13 @@ var buildGraph = (reflexes, effects) => {
71
71
  const existing = runWatchers.get(fact.run) ?? [];
72
72
  runWatchers.set(fact.run, [...existing, reflex.id]);
73
73
  if (fact.run === reflex.id) warnings.push(`${reflex.id} subscribes to its own run \u2014 a drain loop; make sure it narrows`);
74
- if (!byId.has(fact.run)) errors.push(`${reflex.id} watches the run of unknown reflex "${fact.run}"`);
74
+ if (!byId.has(fact.run)) refusals.push({ code: "unknown_reflex", message: `${reflex.id} watches the run of unknown reflex "${fact.run}"` });
75
75
  }
76
76
  }
77
77
  for (const reflex of reflexes) {
78
78
  const handler = effects[reflex.effect.name];
79
79
  if (handler === void 0) {
80
- errors.push(`${reflex.id} names effect "${reflex.effect.name}", which is not registered`);
80
+ refusals.push({ code: "unknown_effect", message: `${reflex.id} names effect "${reflex.effect.name}", which is not registered` });
81
81
  continue;
82
82
  }
83
83
  if (handler.writes === void 0) {
@@ -98,10 +98,11 @@ var buildGraph = (reflexes, effects) => {
98
98
  }));
99
99
  for (const cycle of cycles)
100
100
  if (!cycle.guarded)
101
- errors.push(
102
- `unguarded cycle: ${cycle.reflexIds.join(" \u2192 ")} \u2192 ${cycle.reflexIds[0]} \u2014 no selection and no \`when\` anywhere on the loop, so it diverges by construction`
103
- );
104
- return { edges, cycles, blind, errors, warnings };
101
+ refusals.push({
102
+ code: "unguarded_cycle",
103
+ message: `unguarded cycle: ${cycle.reflexIds.join(" \u2192 ")} \u2192 ${cycle.reflexIds[0]} \u2014 no selection and no \`when\` anywhere on the loop, so it diverges by construction`
104
+ });
105
+ return { edges, cycles, blind, errors: refusals.map((refusal) => refusal.message), refusals, warnings };
105
106
  };
106
107
  var findCycles = (reflexes, edges) => {
107
108
  const adjacency = /* @__PURE__ */ new Map();
@@ -1017,9 +1018,10 @@ var createTide = (config) => {
1017
1018
  parsed.push(result.data);
1018
1019
  }
1019
1020
  const graph = buildGraph(parsed, mergedEffects(parsed));
1020
- if (graph.errors.length > 0)
1021
- throw new TideError("unguarded_cycle", `tide refused to load:
1022
- ${graph.errors.join("\n ")}`, { errors: graph.errors });
1021
+ const refused = graph.refusals[0];
1022
+ if (refused !== void 0)
1023
+ throw new TideError(refused.code, `tide refused to load:
1024
+ ${graph.errors.join("\n ")}`, { errors: graph.errors, refusals: graph.refusals });
1023
1025
  const previously = new Set(loaded.keys());
1024
1026
  const next = /* @__PURE__ */ new Map();
1025
1027
  for (const reflex of parsed) {