Guide

Limiti ed errori

Limita ciò che gli utenti possono fare per piano, gestisci i rifiuti e i codici KymoscopeError.

Impostare i limiti

TypeScript
const engine = createEngine({
  limits: {
    maxChartsPerWorksheet: 4,
    maxChannelsPerChart: 4,
    maxWorksheets: 4,
    maxMathChannels: 4,
    canImportExportWorkspaces: false,
  },
})

// When the user's plan loads or changes:
engine.setOptions({ limits: planLimits })

null significa illimitato. setOptions({ limits }) si unisce ai limiti attuali: le chiavi che ometti mantengono il loro valore.

Quando si raggiunge un limite

Il motore rifiuta l’azione, emette limit e lancia KymoscopeError('limit_reached') con detail.reason.

MotivoAttivato da
charts-per-worksheetcharts.add o io.importChart su un foglio di lavoro pieno.
channels-per-chartcharts.addSeries su un grafico multi-banda pieno.
worksheetsworksheets.add o io.importWorksheet al limite.
workspaces-ioQualsiasi esportazione o importazione io quando canImportExportWorkspaces è false.
math-channelsmathChannels.create, importMany o importFile senza spazio rimasto.
TypeScript
engine.on('limit', ({ reason }) => openUpgradeDialog(reason))

try {
  engine.charts.add('histogram')
} catch (e) {
  if (e instanceof KymoscopeError && e.code === 'limit_reached') return   // the dialog is already open
  throw e
}

Dopo un downgrade

Abbassare i limiti non cancella mai nulla. state.mathChannels elenca solo i canali entro il limite e il foglio di lavoro attivo viene riportato nell’intervallo consentito. I fogli di lavoro e i grafici oltre il limite restano in state.worksheets: tagliali nella tua UI (i primi maxWorksheets fogli e i primi maxChartsPerWorksheet grafici) e tornano quando il limite sale.

Codici di errore

Ogni errore è un KymoscopeError con un code e, dove serve, un oggetto detail. L’elenco completo è in Errori.

TypeScript
import { KymoscopeError } from '@kymoscope/sdk'   // Kymoscope.KymoscopeError with the script tag

function run(fn: () => unknown) {
  Promise.resolve().then(fn).catch((e) => {
    if (e instanceof KymoscopeError && (e.code === 'limit_reached' || e.code === 'import_vetoed')) return
    showError(e instanceof KymoscopeError ? e.code : String(e))
  })
}