Giter Club home page Giter Club logo

Comments (1)

zemberdotnet avatar zemberdotnet commented on September 16, 2024

Sketching ideas.

import { validateRawData } from './rawData';
import { ResourceTagList, ResourceTagMap } from './tagging';

enum EntityClasses {
  DEVICE = 'Device',
}

export interface GraphObject {
  _key: string;
  _type: string;
  _class: string[];
}

export interface Entity extends GraphObject {
  active: boolean;
  [k: string]:
    | string
    | boolean
    | number
    | (string | boolean | number)[]
    | null
    | undefined;
}

export interface Device extends Entity {
  deviceId: string | null;
  make?: string;
}

/**
 * A type representing entity data from a provider.
 */
type ProviderSourceData = {
  /**
   * Some providers include a collection of `tags` that will be stored on the
   * generated entity as `tag.propertyName`, `propertyName` when the tag is
   * registered in `tagProperties` or is known to be a common tag property name,
   * and the tag values will be collected in the generated entity as `tags` (a
   * `string[]`);
   */
  tags?: ResourceTagList | ResourceTagMap;

  [key: string]: any;
};
type GeneratedEntity<T extends Entity> = T & { _rawData: any };

interface NewEntityDataInput<T> {
  entityData: {
    assign: T;
    source: ProviderSourceData;
  };
}

export function createIntegrationEntity<T extends Entity>(
  input: NewEntityDataInput<T>,
): GeneratedEntity<T> {
  const generatedEntity: GeneratedEntity<T> = {
    ...input.entityData.assign,
    _rawData: input.entityData.source,
  };
  validateRawData(generatedEntity);

  return generatedEntity;
}

const d: Device = {
  deviceId: null,
  active: false,
  _key: '',
  _type: '',
  _class: [],
};

const x = createIntegrationEntity<Device>({
  entityData: {
    assign: {
      _class: ['Device'],
      _key: 'a',
      _type: 'b',
      active: false,
      deviceId: 'ss',
      lol: 'x',
    },
    source: {},
  },
});

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.