How to use the @jsii/spec.Stability function in @jsii/spec

To help you get started, we’ve selected a few @jsii/spec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / jsii / packages / jsii-diff / lib / stability.ts View on Github external
function allowedTransitions(start: spec.Stability): spec.Stability[] {
  switch (start) {
    // Experimental can go to stable, external, or be deprecated
    case spec.Stability.Experimental:
      return [spec.Stability.Stable, spec.Stability.Deprecated, spec.Stability.External];

    // Stable can be deprecated, or switched to external
    case spec.Stability.Stable:
      return [spec.Stability.Deprecated, spec.Stability.External];

    // Deprecated can be reinstated
    case spec.Stability.Deprecated:
      return [spec.Stability.Stable, spec.Stability.External];

    // external can be stableified, or deprecated
    case spec.Stability.External:
      return [spec.Stability.Stable, spec.Stability.Deprecated];
  }

  throw new Error(`Unrecognized stability: ${start}`);
}
github aws / jsii / packages / jsii / lib / docs.ts View on Github external
docs.default = eatTag(DocTag.DEFAULT, DocTag.DEFAULT_VALUE);
  docs.deprecated = eatTag(DocTag.DEPRECATED);
  docs.example = eatTag(DocTag.EXAMPLE);
  docs.returns = eatTag(DocTag.RETURNS, DocTag.RETURN);
  docs.see = eatTag(DocTag.SEE);
  docs.subclassable = eatTag(DocTag.SUBCLASSABLE) !== undefined ? true : undefined;

  docs.stability = parseStability(eatTag(DocTag.STABILITY), diagnostics);
  //  @experimental is a shorthand for '@stability experimental', same for '@stable'
  const experimental = eatTag(DocTag.EXPERIMENTAL) !== undefined;
  const stable = eatTag(DocTag.STABLE) !== undefined;
  // Can't combine them
  if (countBools(docs.stability !== undefined, experimental, stable) > 1) {
    diagnostics.push('Use only one of @stability, @experimental or @stable');
  }
  if (experimental) { docs.stability = spec.Stability.Experimental; }
  if (stable) { docs.stability = spec.Stability.Stable; }

  // Can combine '@stability deprecated' with '@deprecated '
  if (docs.deprecated !== undefined) {
    if (docs.stability !== undefined && docs.stability !== spec.Stability.Deprecated) {
      diagnostics.push("@deprecated tag requires '@stability deprecated' or no @stability at all.");
    }
    docs.stability = spec.Stability.Deprecated;
  }

  if (docs.example?.includes('```')) {
    // This is currently what the JSDoc standard expects, and VSCode highlights it in
    // this way as well. TSDoc disagrees and says that examples start in text mode
    // which I tend to agree with, but that hasn't become a widely used standard yet.
    //
    // So we conform to existing reality.
github aws / jsii / packages / jsii-pacmak / lib / targets / dotnet / dotnetruntimegenerator.ts View on Github external
public emitDeprecatedAttributeIfNecessary(obj: spec.Method | spec.ClassType | spec.InterfaceType
  | spec.Property | spec.EnumType | spec.EnumMember | spec.Initializer | undefined): void {
    if (!obj) {
      return;
    }
    const docs = obj.docs;
    if (docs) {
      if (docs.stability! === spec.Stability.Deprecated) {
        const attribute = docs.deprecated ?
          `[System.Obsolete("${docs.deprecated
            .replace(/\n/g, ' ') // Replacing new lines in Obsolete
            .replace(/"/g, '\\"')}")]` : '[System.Obsolete()]';
        this.code.line(attribute);
      }
    }
  }
}
github aws / jsii / packages / jsii-diff / lib / stability.ts View on Github external
function allowedTransitions(start: spec.Stability): spec.Stability[] {
  switch (start) {
    // Experimental can go to stable, external, or be deprecated
    case spec.Stability.Experimental:
      return [spec.Stability.Stable, spec.Stability.Deprecated, spec.Stability.External];

    // Stable can be deprecated, or switched to external
    case spec.Stability.Stable:
      return [spec.Stability.Deprecated, spec.Stability.External];

    // Deprecated can be reinstated
    case spec.Stability.Deprecated:
      return [spec.Stability.Stable, spec.Stability.External];

    // external can be stableified, or deprecated
    case spec.Stability.External:
      return [spec.Stability.Stable, spec.Stability.Deprecated];
  }

  throw new Error(`Unrecognized stability: ${start}`);
}
github aws / jsii / packages / jsii / lib / project-info.ts View on Github external
function _validateStability(stability: string | undefined, deprecated: string | undefined): spec.Stability | undefined {
  if (!stability && deprecated) {
    stability = spec.Stability.Deprecated;
  } else if (deprecated && stability !== spec.Stability.Deprecated) {
    throw new Error(`Package is deprecated (${deprecated}), but it's stability is ${stability} and not ${spec.Stability.Deprecated}`);
  }
  if (!stability) {
    return undefined;
  }
  if (!Object.values(spec.Stability).includes(stability as any)) {
    throw new Error(`Invalid stability "${stability}", it must be one of ${Object.values(spec.Stability).join(', ')}`);
  }
  return stability as spec.Stability;
}
github aws / jsii / packages / jsii / lib / docs.ts View on Github external
function parseStability(s: string | undefined, diagnostics: string[]): spec.Stability | undefined {
  if (s === undefined) { return undefined; }

  switch (s) {
    case 'stable': return spec.Stability.Stable;
    case 'experimental': return spec.Stability.Experimental;
    case 'external': return spec.Stability.External;
    case 'deprecated': return spec.Stability.Deprecated;
  }
  diagnostics.push(`Unrecognized @stability: '${s}'`);
  return undefined;
}
github aws / jsii / packages / jsii / lib / docs.ts View on Github external
function parseStability(s: string | undefined, diagnostics: string[]): spec.Stability | undefined {
  if (s === undefined) { return undefined; }

  switch (s) {
    case 'stable': return spec.Stability.Stable;
    case 'experimental': return spec.Stability.Experimental;
    case 'external': return spec.Stability.External;
    case 'deprecated': return spec.Stability.Deprecated;
  }
  diagnostics.push(`Unrecognized @stability: '${s}'`);
  return undefined;
}
github aws / jsii / packages / jsii / lib / docs.ts View on Github external
function parseStability(s: string | undefined, diagnostics: string[]): spec.Stability | undefined {
  if (s === undefined) { return undefined; }

  switch (s) {
    case 'stable': return spec.Stability.Stable;
    case 'experimental': return spec.Stability.Experimental;
    case 'external': return spec.Stability.External;
    case 'deprecated': return spec.Stability.Deprecated;
  }
  diagnostics.push(`Unrecognized @stability: '${s}'`);
  return undefined;
}
github aws / jsii / packages / jsii / lib / docs.ts View on Github external
function parseStability(s: string | undefined, diagnostics: string[]): spec.Stability | undefined {
  if (s === undefined) { return undefined; }

  switch (s) {
    case 'stable': return spec.Stability.Stable;
    case 'experimental': return spec.Stability.Experimental;
    case 'external': return spec.Stability.External;
    case 'deprecated': return spec.Stability.Deprecated;
  }
  diagnostics.push(`Unrecognized @stability: '${s}'`);
  return undefined;
}
github aws / jsii / packages / jsii / lib / project-info.ts View on Github external
function _validateStability(stability: string | undefined, deprecated: string | undefined): spec.Stability | undefined {
  if (!stability && deprecated) {
    stability = spec.Stability.Deprecated;
  } else if (deprecated && stability !== spec.Stability.Deprecated) {
    throw new Error(`Package is deprecated (${deprecated}), but it's stability is ${stability} and not ${spec.Stability.Deprecated}`);
  }
  if (!stability) {
    return undefined;
  }
  if (!Object.values(spec.Stability).includes(stability as any)) {
    throw new Error(`Invalid stability "${stability}", it must be one of ${Object.values(spec.Stability).join(', ')}`);
  }
  return stability as spec.Stability;
}