@atlaspack/graph 3.4.1-canary.52 → 3.4.1-canary.521

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 (37) hide show
  1. package/CHANGELOG.md +432 -0
  2. package/benchmark/BitSet.js +37 -0
  3. package/dist/AdjacencyList.js +1348 -0
  4. package/dist/BitSet.js +108 -0
  5. package/dist/ContentGraph.js +70 -0
  6. package/dist/Graph.js +504 -0
  7. package/dist/index.js +17 -0
  8. package/dist/shared-buffer.js +24 -0
  9. package/dist/types.js +10 -0
  10. package/lib/AdjacencyList.js +35 -11
  11. package/lib/BitSet.js +36 -5
  12. package/lib/ContentGraph.js +2 -6
  13. package/lib/Graph.js +26 -13
  14. package/lib/index.js +2 -3
  15. package/lib/shared-buffer.js +5 -1
  16. package/lib/types/AdjacencyList.d.ts +609 -0
  17. package/lib/types/BitSet.d.ts +19 -0
  18. package/lib/types/ContentGraph.d.ts +23 -0
  19. package/lib/types/Graph.d.ts +92 -0
  20. package/lib/types/index.d.ts +7 -0
  21. package/lib/types/shared-buffer.d.ts +2 -0
  22. package/lib/types/types.d.ts +9 -0
  23. package/lib/types.js +1 -0
  24. package/package.json +16 -6
  25. package/src/{AdjacencyList.js → AdjacencyList.ts} +135 -107
  26. package/src/{BitSet.js → BitSet.ts} +31 -3
  27. package/src/{ContentGraph.js → ContentGraph.ts} +21 -20
  28. package/src/{Graph.js → Graph.ts} +104 -74
  29. package/src/{index.js → index.ts} +0 -2
  30. package/src/{shared-buffer.js → shared-buffer.ts} +6 -3
  31. package/src/{types.js → types.ts} +5 -7
  32. package/test/{AdjacencyList.test.js → AdjacencyList.test.ts} +21 -29
  33. package/test/{BitSet.test.js → BitSet.test.ts} +45 -5
  34. package/test/{ContentGraph.test.js → ContentGraph.test.ts} +2 -4
  35. package/test/{Graph.test.js → Graph.test.ts} +44 -36
  36. package/tsconfig.json +18 -0
  37. package/tsconfig.tsbuildinfo +1 -0
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import sinon from 'sinon';
5
3
  import path from 'path';
@@ -214,9 +212,7 @@ describe('AdjacencyList', () => {
214
212
 
215
213
  it('addEdge should not replace a deleted edge if the edge was already added', () => {
216
214
  // Mock hash fn to generate collisions
217
- // $FlowFixMe[prop-missing]
218
215
  let originalHash = AdjacencyList.prototype.hash;
219
- // $FlowFixMe[prop-missing]
220
216
  AdjacencyList.prototype.hash = () => 1;
221
217
 
222
218
  let graph = new AdjacencyList();
@@ -229,15 +225,12 @@ describe('AdjacencyList', () => {
229
225
  assert(graph.addEdge(n0, n1, 1) === false);
230
226
  assert(graph.stats.edges === 1);
231
227
 
232
- // $FlowFixMe[prop-missing]
233
228
  AdjacencyList.prototype.hash = originalHash;
234
229
  });
235
230
 
236
231
  it('addEdge should replace a deleted edge', () => {
237
232
  // Mock hash fn to generate collisions
238
- // $FlowFixMe[prop-missing]
239
233
  let originalHash = AdjacencyList.prototype.hash;
240
- // $FlowFixMe[prop-missing]
241
234
  AdjacencyList.prototype.hash = () => 1;
242
235
 
243
236
  try {
@@ -254,7 +247,6 @@ describe('AdjacencyList', () => {
254
247
  assert(graph.stats.edges === 1);
255
248
  assert(graph.stats.deleted === 0);
256
249
  } finally {
257
- // $FlowFixMe[prop-missing]
258
250
  AdjacencyList.prototype.hash = originalHash;
259
251
  }
260
252
  });
@@ -299,8 +291,8 @@ describe('AdjacencyList', () => {
299
291
  graph.addEdge(a, b);
300
292
  graph.addEdge(c, b);
301
293
 
302
- const nodeIds = [];
303
- graph.forEachNodeIdConnectedTo(b, (id) => {
294
+ const nodeIds: Array<any> = [];
295
+ graph.forEachNodeIdConnectedTo(b, (id: any) => {
304
296
  nodeIds.push(id);
305
297
  });
306
298
 
@@ -318,8 +310,8 @@ describe('AdjacencyList', () => {
318
310
  graph.addEdge(b, d);
319
311
  graph.addEdge(c, d);
320
312
 
321
- const nodeIds = [];
322
- graph.forEachNodeIdConnectedTo(d, (nodeId) => {
313
+ const nodeIds: Array<any> = [];
314
+ graph.forEachNodeIdConnectedTo(d, (nodeId: any) => {
323
315
  nodeIds.push(nodeId);
324
316
  return true;
325
317
  });
@@ -337,8 +329,8 @@ describe('AdjacencyList', () => {
337
329
  graph.addEdge(c, b);
338
330
  graph.addEdge(b, b);
339
331
 
340
- const nodeIds = [];
341
- graph.forEachNodeIdConnectedTo(b, (id) => {
332
+ const nodeIds: Array<any> = [];
333
+ graph.forEachNodeIdConnectedTo(b, (id: any) => {
342
334
  nodeIds.push(id);
343
335
  });
344
336
 
@@ -354,8 +346,8 @@ describe('AdjacencyList', () => {
354
346
  graph.addEdge(a, b);
355
347
  graph.addEdge(c, b, 2);
356
348
 
357
- const nodeIds = [];
358
- graph.forEachNodeIdConnectedTo(b, (id) => {
349
+ const nodeIds: Array<any> = [];
350
+ graph.forEachNodeIdConnectedTo(b, (id: any) => {
359
351
  nodeIds.push(id);
360
352
  });
361
353
 
@@ -371,10 +363,10 @@ describe('AdjacencyList', () => {
371
363
  graph.addEdge(a, b);
372
364
  graph.addEdge(c, b, 2);
373
365
 
374
- const nodeIds = [];
366
+ const nodeIds: Array<any> = [];
375
367
  graph.forEachNodeIdConnectedTo(
376
368
  b,
377
- (id) => {
369
+ (id: any) => {
378
370
  nodeIds.push(id);
379
371
  },
380
372
  ALL_EDGE_TYPES,
@@ -413,8 +405,8 @@ describe('AdjacencyList', () => {
413
405
  graph.addEdge(b, d, 3);
414
406
  graph.addEdge(c, e, 4);
415
407
 
416
- const nodeIds = [];
417
- graph.forEachNodeIdConnectedFromReverse(a, (nodeId) => {
408
+ const nodeIds: Array<any> = [];
409
+ graph.forEachNodeIdConnectedFromReverse(a, (nodeId: any) => {
418
410
  nodeIds.push(nodeId);
419
411
  return false;
420
412
  });
@@ -432,8 +424,8 @@ describe('AdjacencyList', () => {
432
424
  graph.addEdge(a, c);
433
425
  graph.addEdge(a, a);
434
426
 
435
- const nodeIds = [];
436
- graph.forEachNodeIdConnectedFromReverse(a, (nodeId) => {
427
+ const nodeIds: Array<any> = [];
428
+ graph.forEachNodeIdConnectedFromReverse(a, (nodeId: any) => {
437
429
  nodeIds.push(nodeId);
438
430
  return false;
439
431
  });
@@ -452,8 +444,8 @@ describe('AdjacencyList', () => {
452
444
  graph.addEdge(a, c);
453
445
  graph.addEdge(a, d);
454
446
 
455
- const nodeIds = [];
456
- graph.forEachNodeIdConnectedFromReverse(a, (nodeId) => {
447
+ const nodeIds: Array<any> = [];
448
+ graph.forEachNodeIdConnectedFromReverse(a, (nodeId: any) => {
457
449
  nodeIds.push(nodeId);
458
450
  return true;
459
451
  });
@@ -472,10 +464,10 @@ describe('AdjacencyList', () => {
472
464
  graph.addEdge(a, c, 2);
473
465
  graph.addEdge(a, d);
474
466
 
475
- const nodeIds = [];
467
+ const nodeIds: Array<any> = [];
476
468
  graph.forEachNodeIdConnectedFromReverse(
477
469
  a,
478
- (nodeId) => {
470
+ (nodeId: any) => {
479
471
  nodeIds.push(nodeId);
480
472
  return false;
481
473
  },
@@ -503,7 +495,7 @@ describe('AdjacencyList', () => {
503
495
  let originalSerialized = graph.serialize();
504
496
  let originalNodes = [...originalSerialized.nodes];
505
497
  let originalEdges = [...originalSerialized.edges];
506
- let work = new Promise((resolve) => worker.on('message', resolve));
498
+ let work = new Promise((resolve: any) => worker.on('message', resolve));
507
499
  worker.postMessage(originalSerialized);
508
500
  let received = AdjacencyList.deserialize(await work);
509
501
  // eslint-disable-next-line no-unused-vars
@@ -512,7 +504,7 @@ describe('AdjacencyList', () => {
512
504
  assert.deepEqual(received.serialize().nodes, graph.serialize().nodes);
513
505
  assert.deepEqual(received.serialize().edges, graph.serialize().edges);
514
506
 
515
- originalNodes.forEach((v, i) => {
507
+ originalNodes.forEach((v: any, i: any) => {
516
508
  if (i < NodeTypeMap.HEADER_SIZE) {
517
509
  assert.equal(v, received.serialize().nodes[i]);
518
510
  assert.equal(v, graph.serialize().nodes[i]);
@@ -522,7 +514,7 @@ describe('AdjacencyList', () => {
522
514
  }
523
515
  });
524
516
 
525
- originalEdges.forEach((v, i) => {
517
+ originalEdges.forEach((v: any, i: any) => {
526
518
  if (i < EdgeTypeMap.HEADER_SIZE) {
527
519
  assert.equal(v, received.serialize().edges[i]);
528
520
  assert.equal(v, graph.serialize().edges[i]);
@@ -1,18 +1,16 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import {BitSet} from '../src/BitSet';
5
3
 
6
4
  function assertValues(set: BitSet, values: Array<number>) {
7
- let setValues = [];
8
- set.forEach((bit) => {
5
+ let setValues: Array<any> = [];
6
+ set.forEach((bit: any) => {
9
7
  setValues.push(bit);
10
8
  });
11
9
 
12
10
  for (let value of values) {
13
11
  assert(set.has(value), 'Set.has returned false');
14
12
  assert(
15
- setValues.some((v) => v === value),
13
+ setValues.some((v: any) => v === value),
16
14
  'Set values is missing value',
17
15
  );
18
16
  }
@@ -107,4 +105,46 @@ describe('BitSet', () => {
107
105
  assertValues(set2, [3, 5]);
108
106
  assertValues(set3, [1, 3, 5]);
109
107
  });
108
+
109
+ it('BitSet.intersect should create a new BitSet with the intersect', () => {
110
+ let set1 = new BitSet(5);
111
+ set1.add(1);
112
+ set1.add(3);
113
+
114
+ let set2 = new BitSet(5);
115
+ set2.add(3);
116
+ set2.add(5);
117
+
118
+ let set3 = BitSet.intersect(set1, set2);
119
+ assertValues(set1, [1, 3]);
120
+ assertValues(set2, [3, 5]);
121
+ assertValues(set3, [3]);
122
+ });
123
+
124
+ it('should identify equality with another BitSet', () => {
125
+ let set1 = new BitSet(5);
126
+ set1.add(1);
127
+ set1.add(3);
128
+
129
+ let set2 = new BitSet(5);
130
+ set2.add(3);
131
+ set2.add(5);
132
+
133
+ let set3 = set1.clone();
134
+
135
+ assert(set1.equals(set3));
136
+ assert(!set1.equals(set2));
137
+ });
138
+
139
+ it('should calculate size of BitSet', () => {
140
+ let set1 = new BitSet(5);
141
+ set1.add(1);
142
+ set1.add(3);
143
+
144
+ assert.equal(set1.size(), 2);
145
+
146
+ set1.add(3);
147
+ set1.add(4);
148
+ assert.equal(set1.size(), 3);
149
+ });
110
150
  });
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import ContentGraph from '../src/ContentGraph';
5
3
 
@@ -7,7 +5,7 @@ describe('ContentGraph', () => {
7
5
  it('should addNodeByContentKey if no node exists with the content key', () => {
8
6
  let graph = new ContentGraph();
9
7
 
10
- const node = {};
8
+ const node: Record<string, any> = {};
11
9
 
12
10
  const nodeId1 = graph.addNodeByContentKey('contentKey', node);
13
11
 
@@ -29,7 +27,7 @@ describe('ContentGraph', () => {
29
27
  it('should remove the content key from graph when node is removed', () => {
30
28
  let graph = new ContentGraph();
31
29
 
32
- const node1 = {};
30
+ const node1: Record<string, any> = {};
33
31
  const nodeId1 = graph.addNodeByContentKey('contentKey', node1);
34
32
 
35
33
  assert.equal(graph.getNode(nodeId1), node1);
@@ -1,11 +1,9 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import sinon from 'sinon';
5
3
  import type {TraversalActions} from '@atlaspack/types-internal';
6
4
 
7
5
  import Graph from '../src/Graph';
8
- import {toNodeId, type NodeId} from '../src/types';
6
+ import {toNodeId, NodeId} from '../src/types';
9
7
 
10
8
  describe('Graph', () => {
11
9
  it('constructor should initialize an empty graph', () => {
@@ -16,7 +14,7 @@ describe('Graph', () => {
16
14
 
17
15
  it('addNode should add a node to the graph', () => {
18
16
  let graph = new Graph();
19
- let node = {};
17
+ let node: Record<string, any> = {};
20
18
  let id = graph.addNode(node);
21
19
  assert.equal(graph.getNode(id), node);
22
20
  });
@@ -340,9 +338,9 @@ describe('Graph', () => {
340
338
 
341
339
  graph.setRootNodeId(nodeA);
342
340
 
343
- let visited = [];
341
+ let visited: Array<any> = [];
344
342
  graph.traverse(
345
- (nodeId) => {
343
+ (nodeId: any) => {
346
344
  visited.push(nodeId);
347
345
  },
348
346
  null, // use root as startNode
@@ -413,7 +411,7 @@ describe('Graph', () => {
413
411
  graph.addEdge(1, 3);
414
412
  graph.addEdge(2, 3);
415
413
 
416
- const order = [];
414
+ const order: Array<any> = [];
417
415
  const visit = (node: NodeId) => {
418
416
  order.push(node);
419
417
  };
@@ -440,10 +438,10 @@ describe('Graph', () => {
440
438
  graph.addEdge(1, 2);
441
439
  graph.addEdge(0, 3);
442
440
 
443
- const order = [];
441
+ const order: Array<any> = [];
444
442
  const visit = (
445
443
  node: NodeId,
446
- context: mixed | null,
444
+ context: unknown | null,
447
445
  actions: TraversalActions,
448
446
  ) => {
449
447
  if (node === 1) actions.skipChildren();
@@ -474,10 +472,10 @@ describe('Graph', () => {
474
472
  graph.addEdge(0, 2);
475
473
  graph.addEdge(2, 3);
476
474
 
477
- const order = [];
475
+ const order: Array<any> = [];
478
476
  const visit = (
479
477
  node: NodeId,
480
- context: mixed | null,
478
+ context: unknown | null,
481
479
  actions: TraversalActions,
482
480
  ) => {
483
481
  order.push(node);
@@ -515,8 +513,8 @@ describe('Graph', () => {
515
513
  graph.addEdge(0, 2);
516
514
  graph.addEdge(2, 3);
517
515
 
518
- const contexts = [];
519
- const visit = (node: NodeId, context: mixed | null) => {
516
+ const contexts: Array<any> = [];
517
+ const visit = (node: NodeId, context: unknown | null) => {
520
518
  contexts.push([node, context]);
521
519
  return `node-${node}-created-context`;
522
520
  };
@@ -528,12 +526,17 @@ describe('Graph', () => {
528
526
  getChildren,
529
527
  });
530
528
 
531
- assert.deepEqual(contexts, [
532
- [0, undefined],
533
- [1, 'node-0-created-context'],
534
- [2, 'node-1-created-context'],
535
- [3, 'node-2-created-context'],
536
- ]);
529
+ assert.deepEqual(
530
+ contexts.map((values: any) =>
531
+ values.map((v: any) => (v != null ? v : undefined)),
532
+ ),
533
+ [
534
+ [0, undefined],
535
+ [1, 'node-0-created-context'],
536
+ [2, 'node-1-created-context'],
537
+ [3, 'node-2-created-context'],
538
+ ],
539
+ );
537
540
  assert.equal(result, undefined);
538
541
  });
539
542
  });
@@ -552,12 +555,12 @@ describe('Graph', () => {
552
555
  graph.addEdge(1, 3);
553
556
  graph.addEdge(0, 2);
554
557
 
555
- const contexts = [];
556
- const visit = (node: NodeId, context: mixed | null) => {
558
+ const contexts: Array<any> = [];
559
+ const visit = (node: NodeId, context: unknown | null) => {
557
560
  contexts.push([node, context]);
558
561
  return `node-${node}-created-context`;
559
562
  };
560
- const visitExit = (node: NodeId, context: mixed | null) => {
563
+ const visitExit = (node: NodeId, context: unknown | null) => {
561
564
  contexts.push(['exit', node, context]);
562
565
  return `node-exit-${node}-created-context`;
563
566
  };
@@ -572,16 +575,21 @@ describe('Graph', () => {
572
575
  getChildren,
573
576
  });
574
577
 
575
- assert.deepEqual(contexts, [
576
- [0, undefined],
577
- [1, 'node-0-created-context'],
578
- [2, 'node-1-created-context'],
579
- ['exit', 2, 'node-2-created-context'],
580
- [3, 'node-1-created-context'],
581
- ['exit', 3, 'node-3-created-context'],
582
- ['exit', 1, 'node-1-created-context'],
583
- ['exit', 0, 'node-0-created-context'],
584
- ]);
578
+ assert.deepEqual(
579
+ contexts.map((values: any) =>
580
+ values.map((v: any) => (v != null ? v : undefined)),
581
+ ),
582
+ [
583
+ [0, undefined],
584
+ [1, 'node-0-created-context'],
585
+ [2, 'node-1-created-context'],
586
+ ['exit', 2, 'node-2-created-context'],
587
+ [3, 'node-1-created-context'],
588
+ ['exit', 3, 'node-3-created-context'],
589
+ ['exit', 1, 'node-1-created-context'],
590
+ ['exit', 0, 'node-0-created-context'],
591
+ ],
592
+ );
585
593
  assert.equal(result, undefined);
586
594
  });
587
595
  });
@@ -602,8 +610,8 @@ describe('Graph', () => {
602
610
  graph.addEdge(a, c);
603
611
  graph.addEdge(c, d);
604
612
 
605
- const order = [];
606
- graph.forEachNodeIdConnectedTo(d, (node) => {
613
+ const order: Array<any> = [];
614
+ graph.forEachNodeIdConnectedTo(d, (node: any) => {
607
615
  order.push(node);
608
616
  });
609
617
 
@@ -626,8 +634,8 @@ describe('Graph', () => {
626
634
  graph.addEdge(a, c);
627
635
  graph.addEdge(c, d);
628
636
 
629
- const order = [];
630
- graph.forEachNodeIdConnectedFrom(a, (node) => {
637
+ const order: Array<any> = [];
638
+ graph.forEachNodeIdConnectedFrom(a, (node: any) => {
631
639
  order.push(node);
632
640
  });
633
641
 
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../dev/babel-register/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../feature-flags/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../types-internal/tsconfig.json"
16
+ }
17
+ ]
18
+ }