Selector.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as _path from 'path';
  2. import * as _util from 'util';
  3. type TemporeryNodeType = any;
  4. export interface ISelector {
  5. describe (showDebug?: boolean): string;
  6. setPropertiesKnownBySelector (node: object): void;
  7. }
  8. export class NodePathSelector {
  9. public value: string;
  10. constructor (path: string) {
  11. this.value = path;
  12. }
  13. public describe (showDebug?: boolean): string {
  14. return this.value;
  15. }
  16. public setPropertiesKnownBySelector (node: TemporeryNodeType): void {
  17. node.path = this.value;
  18. node.name = _path.basename(this.value);
  19. }
  20. }
  21. export class NodeInternalUIDSelector {
  22. public value: string;
  23. constructor (uid: string) {
  24. this.value = uid;
  25. }
  26. public describe (showDebug?: boolean): string {
  27. return `[uid:${this.value}]`;
  28. }
  29. public setPropertiesKnownBySelector (node: TemporeryNodeType): void {
  30. node.uid = this.value;
  31. }
  32. }
  33. export class NodeInternalIDSelector {
  34. constructor (
  35. public service: string,
  36. public id: number,
  37. public debugInfo: any
  38. ) { }
  39. public describe (showDebug?: boolean): string {
  40. if ( showDebug ) {
  41. return `[db:${this.id}] (${
  42. _util.inspect(this.debugInfo)
  43. })`;
  44. }
  45. return `[db:${this.id}]`;
  46. }
  47. public setPropertiesKnownBySelector (node: TemporeryNodeType): void {
  48. if ( this.service === 'mysql' ) {
  49. node.id = this.id;
  50. }
  51. }
  52. }