Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@astrouxds/mock-data

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astrouxds/mock-data

Mock data for use with Astro UXDS demo apps.

  • 0.6.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77
decreased by-82.81%
Maintainers
0
Weekly downloads
 
Created
Source

Astro UXDS Mock Data

Generate "contacts", "alerts" and "mnemonics" data for testing Astro Web Components and building demo applications.

Install

npm install @astrouxds/mock-data

Getting Started

The example below creates a state object with the generated contacts and maps the alerts and mnemonics connected to those contacts on their respective properties.

import { generateContacts } from '@astrouxds/mock-data';

const contacts = generateContacts();

const state = {
  contacts,
  alerts: contacts.flatMap(({ alerts }) => alerts),
  mnemonics: contacts.flatMap(({ mnemonics }) => mnemonics),
};

console.log(state);

Contacts

Contacts include alerts with a "contact ref" on the alert based on where in the array (the index) a contact is. Meaning not all contacts will have alerts, only a percentage of them will.

All contacts will have mnemonics as an array property on the contact object.

import { generateContacts } from '@astrouxds/mock-data';
const contacts = generateContacts(); // returns 100 contacts by default
const contacts = generateContacts(300); // returns 300 contacts
// returns 200 contacts with options provided below
const contacts = generateContacts(200, {
  alertsPercentage: 5, // percentage of the 200 contacts to have an alert @default 10%
  secondAlertPercentage: 3, // percentage of the 200 contacts to have 2 alerts @default 2%
  daysRange: 2, // range of the start and end timestamps @default 1 day
  dateRef: '3/17/2008', // date reference for timestamps @default now
});

Alerts

If you just want alerts without any contact ref you can generate just an array of alerts.

import { generateAlerts } from '@astrouxds/mock-data';
const alerts = generateAlerts(5); // returns 5 alerts

Mnemonics

If you just want mnemonics without any contact ref you can generate just an array of alerts.

import { generateMnemonics } from '@astrouxds/mock-data';
const mnemonics = generateMnemonics(5); // returns 5 mnemonics

Contacts Subscriber

Publishes 100 contacts and generates a new contact every 5 seconds up to 200 contacts by default.

import { onContactsChange } from '@astrouxds/mock-data';
const unsubscribe = onContactsChange((contacts) => {
  console.log(contacts);
});

With options as second argument

const unsubscribe = onContactsChange(
  (contacts) => console.log(contacts),
  { limit: 50 }, // options with a limit of 50
);

Use the unsubscribe function returned from onContactsChange to unsubscribe

setTimeout(() => {
  unsubscribe();
}, 1000 * 60 * 5); // unsubscribe after 5 mins

Contacts Subscriber Example With React

import { useEffect, useState } from 'react';
import { onContactsChange, Contact } from '@astrouxds/mock-data';

const App = () => {
  const [contacts, setContacts] = useState<Contact[]>([]);

  useEffect(() => {
    const unsubscribe = onContactsChange((contacts) => {
      setContacts(contacts);
    });

    return () => {
      unsubscribe();
    };
  }, []);

  return (
    <ul>
      {contacts.map(({ id, equipment }) => (
        <li key={id}>{equipment}</li>
      ))}
    </ul>
  );
};

export default App;

Contacts Service

Class based store for instaciating then subscribing to an auto-generate contacts state

import { ContactsService } from '@astrouxds/mock-data';

// with manually set options
const contactsService = new ContactsService({
  initial: 10,
  interval: 2,
  limit: 20,
});

let contacts: Contact[] = [];
const unsubscribe = contactsService.subscribe((data) => {
  contacts = data;
});

Use the unsubscribe function returned from contactsService.subscribe to unsubscribe

setTimeout(() => {
  unsubscribe();
}, 1000 * 60 * 5); // unsubscribe after 5 mins

API

function

generateContacts

Returns an array of contacts.

Parameters
NameTypeDefaultDescription
lengthnumber100The total number of contacts to generate.
options{...}{}If no options are set, the defaults are used as described below.
options.alertsPercentageAlertsPercentage10The percentage of contacts which should have an alert connected to them.
options.secondAlertPercentageAlertsPercentage2The percentage of contacts which should have two alerts connected to them.
options.daysRangenumber1The range in days for the span between the start and end timestamps.
options.dateRefstring | number | DatenowThe date to reference when generating the contacts.
function

generateContact

Returns a single contact.

Parameters
NameTypeDefaultDescription
indexnumberrequiredThe index is used to determine if an alert(s) is connected the contact.
options{...}{}The same options from generateContacts
function

generateAlerts

Returns an array of alerts.

Parameters
NameTypeDefaultDescription
lengthnumber40The total number of alerts to generate.
options{...}{}If no options are set, the defaults are used as described below.
options.contactRefIdstring''A contact reference id. Will be an empty string if not provided.
options.equipmentstringundefinedAn equipment config string. Will be generated if not provided.
options.createdRefstring | number | DateundefinedThe date to reference when generating the alerts. If provided, this will override any start and end options set.
options.startstring | number | DateundefinedThe starting timestamp for the alert timestamp boundry.
options.endstring | number | DateundefinedThe ending timestamp for the alert timestamp boundry.
function

generateAlert

Returns a single alert.

Parameters
NameTypeDefaultDescription
options{...}{}The same options from generateAlerts

generateMnemonics

Returns an array of menmonics.

Parameters
NameTypeDefaultDescription
lengthnumber9The total number of alerts to generate.
options{...}{}If no options are set, the defaults are used as described below.
options.contactRefIdstring''A contact reference id. Will be an empty string if not provided.
options.thresholdMinnumber0The minimum threshold for the mnemonic value.
options.thresholdMaxnumber110The maximum threshold for the mnemonic value.
options.deviationnumber20The amount the mnemonic value is allow to exceed the threshold maximum or subceed the threshold minimum.
options.precisionnumber0.1The number of decimal places the mnemonic value will include.
function

generateMnemonic

Returns a single mnemonic.

Parameters
NameTypeDefaultDescription
options{...}{}The same options from generateMnemonics
function

onContactsChange

Publishes 100 contacts and generates a new contact every 5 seconds up to 200 contacts by default.

Returns an unsubscribe function.

Parameters
NameTypeDefaultDescription
callback(contacts: Contact[]) => voidrequiredA callback function which receives the latest contacts array.
optionsOnContactChangeOptions{}If no options are set, the defaults are used as described below.
options.alertsPercentageAlertsPercentage10The percentage of contacts which should have an alert connected to them.
options.secondAlertPercentageAlertsPercentage2The percentage of contacts which should have two alerts connected to them.
options.daysRangenumber1The range in days for the span between the start and end timestamps.
options.dateRefstring | number | DatenowThe date to reference when generating the contacts.
options.initialnumber100The initial number of contacts generated on subscribe.
options.intervalnumber5The interval in seconds which new contacts are generated and published.
options.limitnumber200The limit of new contacts to generate and publish.
class

ContactsService

Generates initial contacts, publishes a new contact every x amount of seconds, and has methods to add, update, and delete a contact.

Returns an instance a ContactsService.

Parameters
NameTypeDefaultDescription
optionsContactsServiceOptions{}If no options are set, the defaults are used as described below.
options.alertsPercentageAlertsPercentage10The percentage of contacts which should have an alert connected to them.
options.secondAlertPercentageAlertsPercentage2The percentage of contacts which should have two alerts connected to them.
options.daysRangenumber1The range in days for the span between the start and end timestamps.
options.dateRefstring | number | DatenowThe date to reference when generating the contacts.
options.initialnumber100The initial number of contacts generated on subscribe.
options.intervalnumber5The interval in seconds which new contacts are generated and published.
options.limitnumber200The limit of new contacts to generate and publish.
Methods

subscribe

Subscribes to received published contacts.

Returns a function to unsubscribe.

Parameters
NameTypeDefaultDescription
callback(contacts: Contact[]) => voidrequiredA callback function which receives the latest contacts array.

addContact

Adds a newly generated contact.

Returns the added contact.

Parameters
NameTypeDefaultDescription

updateContact

Updates the specified contact.

Returns a success message.

Parameters
NameTypeDefaultDescription
iduuidrequiredThe id of the contact to modify.
paramsUpdateContactParams{}An optional params object.
params.groundContactGroundundefinedOptional property to modify.
params.satellitestringundefinedOptional property to modify.
params.equipmentstringundefinedOptional property to modify.
params.stateContactStateundefinedOptional property to modify.
params.stepContactStepundefinedOptional property to modify.
params.detailstringundefinedOptional property to modify.
params.beginTimestampnumberundefinedOptional property to modify.
params.endTimestampnumberundefinedOptional property to modify.
params.resolutionContactResolutionundefinedOptional property to modify.
params.resolutionStatusContactResolutionStatusundefinedOptional property to modify.

deleteContact

Deletes the specified contact.

Returns a success message.

Parameters
NameTypeDefaultDescription
iduuidrequiredThe id of the contact to delete.

Schema

Types

TypeDescription
AlertCategory'software' | 'spacecraft' | 'hardware'
AlertsPercentage0 | 2 | 3 | 4 | 5 | 10 | 12 | 15 | 20 | 25 | 34 | 50
ContactGround'CTS' | 'DGS' | 'GTS' | 'TCS' | 'VTS' | 'NHS' | 'TTS' | 'HTS'
ContactState'executing' | 'failed' | 'ready' | 'updating'
ContactStep'AOS' | 'Command' | 'Configure Operation' | 'Critical Health' | 'DCC' | 'Downlink' | 'Lock' | 'LOS' | 'SARM'| 'Uplink'
ContactResolution'complete' | 'failed' | 'pass' | 'prepass' | 'scheduled'
ContactResolutionStatus'normal' | 'critical' | 'off' | 'standby'
DataType'contact' | 'alert' | 'mnemonic'
Status'caution' | 'critical' | 'normal' | 'off' | 'serious' | 'standby'

Contact

PropertyTypeDescription
idstringuuid
typeDataType
statusStatus
namenumber
groundContactGround
revnumber
satellitestring
equipmentstring
stateContactState
stepContactStep
detailstring
beginTimestampnumber
endTimestampnumber
aosnumber
losnumber
latitudenumber
longitudenumber
azimuthnumber
elevationnumber
resolutionContactResolution
resolutionStatusContactResolutionStatus
alertsAlert[]An array of alerts.
mnemonicsMnemonic[]An array of mnemonics.

Alert

PropertyTypeDescription
idstringuuid
statusStatus
categoryAlertCategory
messagestring
longMessagestring
timestampnumber
selectedboolean
newboolean
expandedboolean
acknowledgedboolean
contactRefIdstringuuid | ''

Mnemonic

PropertyTypeDescription
idstringuuid
mnemonicIdstring
statusStatus
unitstring
thresholdMaxnumber
thresholdMinnumber
currentValuenumber
subsystemstring
childSubsystemstring
measurementstring
contactRefIdstringuuid | ''

FAQs

Package last updated on 02 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc