Skip to content

Commit

Permalink
Merge pull request #2925 from quantified-uncertainty/api-deprecate-ti…
Browse files Browse the repository at this point in the history
…tles-Tag.all

Deprecate Plot Titles, Tag.all -> Tag.getAll
  • Loading branch information
OAGr committed Jan 9, 2024
2 parents ff5fafb + 7c290ab commit 152df1a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-peaches-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@quri/squiggle-lang": patch
---

Breaking: Deprecates Plot titles, changes Tag.all -> Tag.getAll
6 changes: 3 additions & 3 deletions packages/squiggle-lang/__tests__/library/tag_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("Tags", () => {

describe("all", () => {
testEvalToBe(
"123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.all",
"123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.getAll",
'{name: "myName",doc: "myDoc"}'
);
});
Expand All @@ -22,14 +22,14 @@ describe("Tags", () => {

describe("omit", () => {
testEvalToBe(
"123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.format('.2%') -> Tag.omit(['name', 'doc']) -> Tag.all",
"123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.format('.2%') -> Tag.omit(['name', 'doc']) -> Tag.getAll",
'{numberFormat: ".2%"}'
);
});

describe("clear", () => {
testEvalToBe(
"123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.format('.2%') -> Tag.clear -> Tag.all",
"123 -> Tag.name('myName') -> Tag.doc('myDoc') -> Tag.format('.2%') -> Tag.clear -> Tag.getAll",
"{}"
);
});
Expand Down
19 changes: 10 additions & 9 deletions packages/squiggle-lang/src/fr/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { makeDefinition } from "../library/registry/fnDefinition.js";
import {
frArray,
frBool,
frDeprecated,
frDict,
frDist,
frDistOrNumber,
Expand Down Expand Up @@ -183,7 +184,7 @@ const numericFnDef = () => {
frDict(
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["xPoints", frOptional(frArray(frNumber))]
)
)
Expand All @@ -207,7 +208,7 @@ const numericFnDef = () => {
["fn", fnType],
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["xPoints", frOptional(frArray(frNumber))]
),
],
Expand Down Expand Up @@ -251,7 +252,7 @@ export const library = [
frDict(
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["showSummary", frOptional(frBool)]
)
)
Expand All @@ -276,7 +277,7 @@ export const library = [
["dist", frDist],
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["showSummary", frOptional(frBool)]
),
],
Expand Down Expand Up @@ -329,7 +330,7 @@ export const library = [
frDict(
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["showSummary", frOptional(frBool)]
)
),
Expand Down Expand Up @@ -373,7 +374,7 @@ export const library = [
],
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["showSummary", frOptional(frBool)]
),
],
Expand Down Expand Up @@ -426,7 +427,7 @@ export const library = [
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["distXScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["xPoints", frOptional(frArray(frNumber))]
)
)
Expand Down Expand Up @@ -456,7 +457,7 @@ export const library = [
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["distXScale", frOptional(frScale)],
["title", frOptional(frString)],
["title", frDeprecated(frOptional(frString))],
["xPoints", frOptional(frArray(frNumber))]
),
],
Expand Down Expand Up @@ -507,7 +508,7 @@ Plot.scatter({
["yDist", frWithTags(frSampleSetDist)],
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)]
["title", frDeprecated(frOptional(frString))]
),
],
frPlot,
Expand Down
3 changes: 2 additions & 1 deletion packages/squiggle-lang/src/fr/relativeValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { sq } from "../index.js";
import { makeDefinition } from "../library/registry/fnDefinition.js";
import {
frArray,
frDeprecated,
frDict,
frLambdaTyped,
frNumber,
Expand All @@ -21,7 +22,7 @@ const maker = new FnFactory({
const relativeValuesShape = frDict(
["ids", frArray(frString)],
["fn", frLambdaTyped([frString, frString], frArray(frNumber))],
["title", frOptional(frString)]
["title", frDeprecated(frOptional(frString))]
);

export const library = [
Expand Down
2 changes: 1 addition & 1 deletion packages/squiggle-lang/src/fr/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Different types of values can be displayed in different ways. The following tabl
],
}),
maker.make({
name: "all",
name: "getAll",
displaySection: "Functions",
description: "Returns a dictionary of all tags on a value.",
definitions: [
Expand Down
16 changes: 16 additions & 0 deletions packages/squiggle-lang/src/library/registry/frTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const isOptional = <T>(frType: FRType<T>): boolean => {
return frType.isOptional === undefined ? false : frType.isOptional;
};

export const isDeprecated = <T>(frType: FRType<T>): boolean => {
return frType.tag === "deprecated";
};

export const frNumber: FRType<number> = {
unpack: (v: Value) => (v.type === "Number" ? v.value : undefined),
pack: (v) => vNumber(v),
Expand Down Expand Up @@ -552,6 +556,7 @@ export function frDict<T extends object>(
display: () =>
"{" +
allKvs
.filter(([_, frType]) => !isDeprecated(frType))
.map(
([name, frType]) =>
`${name}${isOptional(frType) ? "?" : ""}: ${frType.display()}`
Expand Down Expand Up @@ -596,3 +601,14 @@ export const frOptional = <T>(itemType: FRType<T>): FRType<T | null> => {
fieldType: itemType.fieldType,
};
};

export const frDeprecated = <T>(itemType: FRType<T>): FRType<T> => ({
unpack: itemType.unpack,
pack: (v) => itemType.pack(v),
display: () => ``,
isOptional: isOptional(itemType),
tag: "deprecated",
underlyingType: itemType,
default: itemType.default,
fieldType: itemType.fieldType,
});

2 comments on commit 152df1a

@vercel
Copy link

@vercel vercel bot commented on 152df1a Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 152df1a Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.