Skip to content

Commit 2dfef6b

Browse files
authored
Merge pull request #34 from glideapps/arrays
Arrays and released flag
2 parents 0e11a67 + 0a35146 commit 2dfef6b

11 files changed

+70
-10
lines changed

src/columns/app-icon.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function fetchAppIcon(
3232

3333
const run: glide.Column = async url => {
3434
if (url.value === undefined) return undefined;
35-
return await cache.getWith(url.value, fetchAppIcon);
35+
return await cache.getWith(url.value.toString(), fetchAppIcon);
3636
};
3737

3838
export default glide.column({

src/columns/capitalize.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import capitalize from "lodash/capitalize";
55
export default glide
66
.columnNamed("Capitalize Text")
77
.withCategory("Text")
8+
.withReleased("direct")
89
.withDescription(
910
`Converts the first character of string to upper case and the remaining to lower case.`
1011
)

src/columns/clamp.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as glide from "../glide";
33
export default glide
44
.columnNamed("Clamp")
55
.withCategory("Number")
6+
.withReleased("direct")
67
.withDescription(`Clamps a number within inclusive lower and upper bounds.`)
78
.withNumberResult()
89
.withRequiredNumberParam("number")

src/columns/fetch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const run: glide.Column = async (url, query) => {
1111
if (url.value === undefined) {
1212
return undefined;
1313
}
14-
let data = await cache.fetch(url.value);
14+
let data = await cache.fetch(url.value.toString());
1515
if (query.value !== undefined) {
1616
data = jq.json(data, query.value);
1717
}

src/columns/glide-brand-image.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const run: glide.Column = async (categoryValue, randomSeed) => {
1818
const images = await cache.fetch(
1919
`https://column.sh/glide-brand-image/images.json`
2020
);
21-
const is = images[category] ?? images[defaultCategory];
22-
const random = seedrandom(seed)();
21+
const is = images[category.toString()] ?? images[defaultCategory];
22+
const random = seedrandom(seed.toString())();
2323
const image = is[Math.floor(random * is.length)];
2424

2525
// TODO move these images to CDN, not Vercel

src/columns/hell-yes-code.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ const run: glide.Column = async (code, ...params) => {
1212
// TODO https://esbuild.github.io/content-types/#direct-eval
1313
const fn = (0, eval)(functionCode);
1414

15-
functions.set(code.value, fn);
15+
functions.set(code.value.toString(), fn);
1616

1717
return fn(...params.map(p => p.value));
1818
};
1919

2020
export default glide.column({
2121
name: "Hell Yes-Code",
2222
category: "Code",
23+
released: "sandboxed",
2324
description: "Runs JavaScript",
2425
about: `Inludes [lodash](https://lodash.com/docs).`,
2526
author: "Mark Probst <[email protected]>",

src/columns/hyperformula.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const run: glide.Column = async (formula, ...params) => {
1919
export default glide.column({
2020
name: "Hyperformula",
2121
category: "Code",
22+
released: "sandboxed",
2223
description: "Run Excel formulas",
2324
about: `
2425
Uses [handsontable.github.io/hyperformula](https://handsontable.github.io/hyperformula) to evaluate

src/columns/jq.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const run: glide.Column = async (json, query) => {
1010
return json.value;
1111
}
1212

13-
const val = jq.json(JSON.parse(json.value), query.value);
13+
const val = jq.json(JSON.parse(json.value.toString()), query.value);
1414

1515
if (val === null) {
1616
return undefined;

src/columns/reverse-array.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as glide from "../glide";
2+
3+
export default glide
4+
.columnNamed("Reverse Array")
5+
.withDescription(
6+
"Reverses the order of items in an array"
7+
)
8+
.withReleased("direct")
9+
.withPrimitiveArrayResult()
10+
.withPrimitiveArrayParam("array")
11+
.run(({ array }) => {
12+
if (array === undefined) return undefined;
13+
return [...array].reverse();
14+
});

src/columns/youtube-thumbnail.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const run: glide.Column = async link => {
1818
if (link.value === undefined) {
1919
return undefined;
2020
}
21-
return thumbnailFromLink(link.value);
21+
return thumbnailFromLink(link.value.toString());
2222
};
2323

2424
export default glide.column({

src/glide.ts

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import startCase from "lodash/startCase";
22

3-
export type ColumnType =
3+
export type PrimitiveColumnType =
44
| "string"
55
| "primitive"
66
| "number"
@@ -9,6 +9,8 @@ export type ColumnType =
99
| "date-time"
1010
| "uri";
1111

12+
export type ColumnType = PrimitiveColumnType | { kind: "array", items: PrimitiveColumnType };
13+
1214
export type StringColumnValue = { type: "string"; value?: string };
1315

1416
export type ColumnParam = {
@@ -17,9 +19,12 @@ export type ColumnParam = {
1719
type: ColumnType;
1820
};
1921

22+
export type PrimitiveValue = string | number | boolean;
23+
2024
export type ColumnValue =
21-
| { type: "primitive"; value?: any }
25+
| { type: "primitive"; value?: PrimitiveValue }
2226
| { type: "number"; value?: number }
27+
| { type: "boolean"; value?: boolean }
2328
| StringColumnValue;
2429

2530
export type Column = (...values: ColumnValue[]) => any | Promise<any>;
@@ -79,9 +84,12 @@ export type Category =
7984
| "Date & Time"
8085
| "Code";
8186

87+
type Released = "direct" | "sandboxed";
88+
8289
export type Manifest = {
8390
name: string;
8491
category: Category;
92+
released?: Released;
8593
description: string;
8694
author: string;
8795
params: ColumnParam[];
@@ -149,7 +157,7 @@ export function toStrictManifest(
149157
): Manifest {
150158
// We carefully pick out just the props in manifest, because more
151159
// could come in from the component.
152-
const { name, category, description, author, result, params, about, video } =
160+
const { name, category, released, description, author, result, params, about, video } =
153161
convenient;
154162

155163
let { icon = defaultIcon } = convenient;
@@ -160,6 +168,7 @@ export function toStrictManifest(
160168
return {
161169
name,
162170
category,
171+
released,
163172
description,
164173
author,
165174
result,
@@ -176,6 +185,7 @@ export function toStrictManifest(
176185
const defaultDefinition: ColumnDefinition = {
177186
name: "Glide Column",
178187
category: "General",
188+
released: undefined,
179189
description: "No description",
180190
author: "Glide <[email protected]>",
181191
params: {},
@@ -222,6 +232,10 @@ export class Col<TParams = {}, TResult = string> {
222232
return this.with({ category });
223233
}
224234

235+
public withReleased(released: "direct" | "sandboxed") {
236+
return this.with({ released })
237+
}
238+
225239
public withDescription(description: string) {
226240
return this.with({ description });
227241
}
@@ -273,6 +287,18 @@ export class Col<TParams = {}, TResult = string> {
273287
return this.withResult<boolean>("boolean");
274288
}
275289

290+
public withStringArrayResult() {
291+
return this.withResult<string[]>({ kind: "array", items: "string"});
292+
}
293+
294+
public withNumberArrayResult() {
295+
return this.withResult<number[]>({ kind: "array", items: "number"});
296+
}
297+
298+
public withPrimitiveArrayResult() {
299+
return this.withResult<PrimitiveValue[]>({ kind: "array", items: "primitive"});
300+
}
301+
276302
public withParam<TParam, TName extends string>(
277303
type: ColumnType,
278304
name: TName,
@@ -341,6 +367,22 @@ export class Col<TParams = {}, TResult = string> {
341367
return this.withRequiredParam<number, T>("number", name, displayName);
342368
}
343369

370+
public withStringArrayParam<T extends string>(name: T, displayName?: string) {
371+
return this.withParam<string[], T>({ kind: "array", items: "string"}, name, displayName);
372+
}
373+
374+
public withNumberArrayParam<T extends string>(name: T, displayName?: string) {
375+
return this.withParam<number[], T>({ kind: "array", items: "number"}, name, displayName);
376+
}
377+
378+
public withPrimitiveArrayParam<T extends string>(name: T, displayName?: string) {
379+
return this.withParam<PrimitiveValue[], T>({ kind: "array", items: "primitive"}, name, displayName);
380+
}
381+
382+
public withExample(example: TParams) {
383+
return this.with({ example });
384+
}
385+
344386
public run(
345387
columnFunction: (
346388
params: TParams

0 commit comments

Comments
 (0)