@groma/scanner-javascript 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +15 -15
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -118,13 +118,13 @@ function compare(...values) {
118
118
  }
119
119
  function uniqueBy(values, key, label) {
120
120
  const seen = new Set;
121
- for (const value of values) {
122
- const id = key(value);
121
+ const keyed = values.map((value) => ({ id: key(value), value }));
122
+ for (const { id } of keyed) {
123
123
  if (seen.has(id))
124
124
  throw new Error(`duplicate ${label}: ${id}`);
125
125
  seen.add(id);
126
126
  }
127
- return [...values].sort((left, right) => key(left).localeCompare(key(right)));
127
+ return keyed.sort((left, right) => left.id.localeCompare(right.id)).map((entry) => entry.value);
128
128
  }
129
129
  function createScanObservation(input) {
130
130
  const roots = validateRoots(input.roots);
@@ -135,9 +135,7 @@ function createScanObservation(input) {
135
135
  symbols: [...new Map(file.symbols.map((symbol) => [
136
136
  compare(symbol.id, symbol.kind),
137
137
  symbol
138
- ])).values()].sort((left, right) => {
139
- return compare(left.id, left.kind).localeCompare(compare(right.id, right.kind));
140
- })
138
+ ]))].sort(([left], [right]) => left.localeCompare(right)).map(([, symbol]) => symbol)
141
139
  })), (file) => file.file, "file path");
142
140
  const filePaths = new Set(files.map((file) => file.file));
143
141
  for (const file of files) {
@@ -148,8 +146,6 @@ function createScanObservation(input) {
148
146
  throw new Error(`file references unknown root: ${root}`);
149
147
  }
150
148
  }
151
- for (const diagnostic of input.diagnostics)
152
- diagnosticLocation(diagnostic);
153
149
  return {
154
150
  schemaVersion: 1,
155
151
  scanner: input.scanner,
@@ -159,14 +155,14 @@ function createScanObservation(input) {
159
155
  ...entryPoints(input.entryPoints, filePaths),
160
156
  ...operationEvidence(input, filePaths),
161
157
  ...httpEvidence(input.httpEndpoints, input.httpRequests, input.operations && new Set(input.operations.map((operation) => operation.id))),
162
- diagnostics: [...new Map(input.diagnostics.map((diagnostic) => [
163
- diagnosticKey(diagnostic),
164
- diagnostic
165
- ])).values()].sort((left, right) => {
166
- return diagnosticKey(left).localeCompare(diagnosticKey(right));
167
- })
158
+ diagnostics: normalizeScanDiagnostics(input.diagnostics)
168
159
  };
169
160
  }
161
+ function normalizeScanDiagnostics(diagnostics) {
162
+ for (const diagnostic of diagnostics)
163
+ diagnosticLocation(diagnostic);
164
+ return [...new Map(diagnostics.map((diagnostic) => [diagnosticKey(diagnostic), diagnostic]))].sort(([left], [right]) => left.localeCompare(right)).map(([, diagnostic]) => diagnostic);
165
+ }
170
166
  function entryPoints(input, paths) {
171
167
  if (input === undefined)
172
168
  return {};
@@ -275,10 +271,14 @@ function operationTokens(operation) {
275
271
  const endLine = Number(operation.endLine);
276
272
  if (endLine < startLine)
277
273
  throw new Error("operation.endLine must be at or after startLine");
274
+ const tokens = array(operation.tokens, "operation.tokens");
275
+ tokens.forEach((token) => {
276
+ string(token, "operation.token");
277
+ });
278
278
  return {
279
279
  startLine,
280
280
  endLine,
281
- tokens: array(operation.tokens, "operation.tokens").map((token) => string(token, "operation.token"))
281
+ tokens
282
282
  };
283
283
  }
284
284
  function validateOperationTokens(operation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groma/scanner-javascript",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "JavaScript source declarations, outlines and operation bodies without project dependencies.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "repository": {
57
57
  "type": "git",
58
- "url": "https://github.com/MrLesk/Groma.md.git"
58
+ "url": "https://github.com/MrLesk/groma.md.git"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"