@weborigami/origami 0.0.48 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/exports/buildExports.js +2 -2
  2. package/exports/exports.js +29 -13
  3. package/index.ts +0 -3
  4. package/package.json +10 -10
  5. package/src/builtins/@addNextPrevious.js +58 -0
  6. package/src/builtins/{@arrows.js → @arrowsMap.js} +7 -7
  7. package/src/builtins/@changes.js +46 -0
  8. package/src/builtins/@clean.js +19 -0
  9. package/src/builtins/@constructor.js +17 -0
  10. package/src/builtins/@crawl.js +2 -2
  11. package/src/builtins/@debug.js +17 -19
  12. package/src/builtins/@deepMap.js +19 -0
  13. package/src/builtins/@deepMapFn.js +25 -0
  14. package/src/builtins/{@mergeDeep.js → @deepMerge.js} +7 -7
  15. package/src/builtins/@deepTake.js +21 -0
  16. package/src/builtins/@deepTakeFn.js +22 -0
  17. package/src/builtins/{@valuesDeep.js → @deepValues.js} +6 -5
  18. package/src/builtins/@document.js +1 -2
  19. package/src/builtins/@files.js +14 -1
  20. package/src/builtins/@group.js +20 -0
  21. package/src/builtins/@groupFn.js +30 -0
  22. package/src/builtins/@if.js +2 -1
  23. package/src/builtins/@image/format.js +10 -31
  24. package/src/builtins/@image/formatFn.js +15 -0
  25. package/src/builtins/@image/resize.js +7 -28
  26. package/src/builtins/@image/resizeFn.js +14 -0
  27. package/src/builtins/@inline.js +8 -2
  28. package/src/builtins/@invoke.js +1 -1
  29. package/src/builtins/@json.js +5 -1
  30. package/src/builtins/@jsonParse.js +9 -0
  31. package/src/builtins/@map.js +10 -170
  32. package/src/builtins/@mapFn.js +143 -0
  33. package/src/builtins/@mdHtml.js +2 -0
  34. package/src/builtins/@mdTree.js +69 -0
  35. package/src/builtins/@naturalOrder.js +1 -0
  36. package/src/builtins/@ori.js +1 -1
  37. package/src/builtins/@paginate.js +18 -0
  38. package/src/builtins/@paginateFn.js +61 -0
  39. package/src/builtins/@perf.js +1 -1
  40. package/src/builtins/@redirect.js +10 -1
  41. package/src/builtins/@regexParse.js +5 -0
  42. package/src/builtins/@regexParseFn.js +9 -0
  43. package/src/builtins/@rss.js +8 -4
  44. package/src/builtins/@sitemap.js +4 -4
  45. package/src/builtins/@slug.js +15 -0
  46. package/src/builtins/@sort.js +10 -7
  47. package/src/builtins/@sortFn.js +58 -0
  48. package/src/builtins/@take.js +3 -17
  49. package/src/builtins/@takeFn.js +21 -0
  50. package/src/builtins/@tree.js +2 -14
  51. package/src/builtins/@yaml.js +4 -0
  52. package/src/builtins/@yamlParse.js +10 -0
  53. package/src/builtins/map.d.ts +6 -7
  54. package/src/common/ExplorableSiteTransform.js +16 -10
  55. package/src/common/ShuffleTransform.js +3 -3
  56. package/src/common/{arrowFunctionsMap.js → arrowsMapFn.js} +3 -3
  57. package/src/common/documentObject.js +18 -9
  58. package/src/common/serialize.js +1 -10
  59. package/src/common/utilities.js +5 -2
  60. package/src/misc/OriCommandTransform.js +2 -7
  61. package/src/misc/explore.ori +7 -7
  62. package/src/server/constructResponse.js +3 -9
  63. package/src/server/server.js +5 -2
  64. package/src/builtins/@apply.js +0 -6
  65. package/src/builtins/@groupBy.js +0 -37
  66. package/src/builtins/@isAsyncTree.js +0 -17
  67. package/src/builtins/@mapDeep.js +0 -22
  68. package/src/builtins/@new.js +0 -6
  69. package/src/builtins/@parse/json.js +0 -6
  70. package/src/builtins/@parse/yaml.js +0 -8
  71. package/src/builtins/@sortBy.js +0 -37
  72. package/src/builtins/@with.js +0 -22
@@ -25,7 +25,7 @@ export default async function constructResponse(request, resource) {
25
25
  if (resource instanceof Response) {
26
26
  // Already a Response, return as is.
27
27
  return resource;
28
- } else if (!resource) {
28
+ } else if (resource == null) {
29
29
  return null;
30
30
  }
31
31
 
@@ -42,14 +42,8 @@ export default async function constructResponse(request, resource) {
42
42
  mediaType = extension ? mediaTypeForExtension[extension] : undefined;
43
43
  }
44
44
 
45
- if (
46
- mediaType === undefined &&
47
- !url.pathname.endsWith("/") &&
48
- (Tree.isAsyncTree(resource) ||
49
- isPlainObject(resource) ||
50
- resource instanceof Array)
51
- ) {
52
- // Redirect to an index page for the result.
45
+ if (!url.pathname.endsWith("/") && Tree.isTreelike(resource)) {
46
+ // Treelike resource: redirect to its index page.
53
47
  const Location = `${request.url}/`;
54
48
  return new Response("ok", {
55
49
  headers: {
@@ -120,8 +120,11 @@ function keysFromUrl(url) {
120
120
  pathKeys[pathKeys.length - 1] = "index.html";
121
121
  }
122
122
 
123
- // Add back the `!` to commands.
124
- const commandKeys = parts.map((command) => `!${command}`);
123
+ // Decode the text of the commands, prefix spaces with a backslash, and add
124
+ // back the `!` character.
125
+ const commandKeys = parts.map(
126
+ (command) => `!${decodeURIComponent(command).replace(/ /g, "\\ ")}`
127
+ );
125
128
 
126
129
  const keys = [...pathKeys, ...commandKeys];
127
130
  return keys;
@@ -1,6 +0,0 @@
1
- /**
2
- * @this {import("@weborigami/types").AsyncTree|null}
3
- */
4
- export default async function apply(target, fn) {
5
- return fn.call(this, target);
6
- }
@@ -1,37 +0,0 @@
1
- import { groupBy } from "@weborigami/async-tree";
2
- import { Scope } from "@weborigami/language";
3
- import addValueKeyToScope from "../common/addValueKeyToScope.js";
4
- import { toFunction } from "../common/utilities.js";
5
- import getTreeArgument from "../misc/getTreeArgument.js";
6
-
7
- /**
8
- * Return a new tree with the values from the original tree in groups.
9
- * The groups are determined by the given function.
10
- *
11
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
12
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
13
- * @typedef {import("../../index.ts").Invocable} Invocable
14
- *
15
- * @this {AsyncTree|null}
16
- * @param {Treelike} treelike
17
- * @param {Invocable} groupKeyFn
18
- */
19
- export default async function groupByBuiltin(treelike, groupKeyFn) {
20
- const tree = await getTreeArgument(this, arguments, treelike, "@groupBy");
21
-
22
- const fn = toFunction(groupKeyFn);
23
- const baseScope = Scope.getScope(this);
24
- async function extendedGroupKeyFn(value, key, tree) {
25
- const scope = addValueKeyToScope(baseScope, value, key);
26
- const sortKey = await fn.call(scope, value, key);
27
- return sortKey;
28
- }
29
-
30
- const grouped = await groupBy(extendedGroupKeyFn)(tree);
31
- const scoped = Scope.treeWithScope(grouped, this);
32
- return scoped;
33
- }
34
-
35
- groupByBuiltin.usage = `@groupBy <tree>, [groupKeyFn]\tReturn a new tree with the original's values grouped`;
36
- groupByBuiltin.documentation =
37
- "https://weborigami.org/cli/builtins.html#@group";
@@ -1,17 +0,0 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
-
3
- import { Tree } from "@weborigami/async-tree";
4
-
5
- /**
6
- * Return true if the value is an async tree.
7
- *
8
- * @this {AsyncTree|null}
9
- * @param {any} value
10
- */
11
- export default function isAsyncTree(value) {
12
- return Tree.isAsyncTree(value);
13
- }
14
-
15
- isAsyncTree.usage = `@isAsyncTree <value>\tReturn true for an async tree`;
16
- isAsyncTree.documentation =
17
- "https://weborigami.org/cli/builtins.html#isAsyncTree";
@@ -1,22 +0,0 @@
1
- import { isPlainObject } from "@weborigami/async-tree";
2
- import treeMap from "./@map.js";
3
-
4
- export default function mapDeep(param1, param2) {
5
- // Identify whether the valueFn/options are the first parameter
6
- // or the second.
7
- let source;
8
- let options;
9
- if (param2 === undefined) {
10
- options = param1;
11
- } else {
12
- source = param1;
13
- if (isPlainObject(param2)) {
14
- options = param2;
15
- } else {
16
- options = { value: param2 };
17
- }
18
- }
19
-
20
- options.deep = true;
21
- return treeMap(source, options);
22
- }
@@ -1,6 +0,0 @@
1
- export default function newBuiltin(constructor, ...args) {
2
- return Reflect.construct(constructor, args);
3
- }
4
-
5
- newBuiltin.usage = "@new <classFn>\tCreate a new instance of the given class";
6
- newBuiltin.documentation = "https://weborigami.org/language/@new.html";
@@ -1,6 +0,0 @@
1
- export default async function parseJson(text) {
2
- return text ? JSON.parse(text) : undefined;
3
- }
4
-
5
- parseJson.usage = `parseJson <text>\tParse text as JSON`;
6
- parseJson.documentation = "https://weborigami.org/cli/builtins.html#parseJson";
@@ -1,8 +0,0 @@
1
- import * as serialize from "../../common/serialize.js";
2
-
3
- export default async function parseYaml(text) {
4
- return text ? serialize.parseYaml(String(text)) : undefined;
5
- }
6
-
7
- parseYaml.usage = `parseYaml <text>\tParse text as YAML (including JSON)`;
8
- parseYaml.documentation = "https://weborigami.org/cli/builtins.html#parseYaml";
@@ -1,37 +0,0 @@
1
- import { sortBy } from "@weborigami/async-tree";
2
- import { Scope } from "@weborigami/language";
3
- import addValueKeyToScope from "../common/addValueKeyToScope.js";
4
- import { toFunction } from "../common/utilities.js";
5
- import getTreeArgument from "../misc/getTreeArgument.js";
6
-
7
- /**
8
- * Return a new tree with the original's keys sorted using the given function to
9
- * obtain a sort key for each value in the tree.
10
- *
11
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
12
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
13
- * @typedef {import("../../index.ts").Invocable} Invocable
14
- *
15
- * @this {AsyncTree|null}
16
- * @param {Treelike} treelike
17
- * @param {Invocable} sortKeyFn
18
- */
19
- export default async function sortByBuiltin(treelike, sortKeyFn) {
20
- const tree = await getTreeArgument(this, arguments, treelike, "@sortBy");
21
-
22
- const fn = toFunction(sortKeyFn);
23
- const baseScope = Scope.getScope(this);
24
- async function extendedSortKeyFn(key, tree) {
25
- const value = await tree.get(key);
26
- const scope = addValueKeyToScope(baseScope, value, key);
27
- const sortKey = await fn.call(scope, value, key);
28
- return sortKey;
29
- }
30
-
31
- const sorted = sortBy(extendedSortKeyFn)(tree);
32
- const scoped = Scope.treeWithScope(sorted, this);
33
- return scoped;
34
- }
35
-
36
- sortByBuiltin.usage = `@sortBy <tree>, [sortKeyFn]\tReturn a new tree with the original's keys sorted`;
37
- sortByBuiltin.documentation = "https://weborigami.org/cli/builtins.html#@sort";
@@ -1,22 +0,0 @@
1
- import { Tree } from "@weborigami/async-tree";
2
- import { Scope } from "@weborigami/language";
3
- import { toFunction } from "../common/utilities.js";
4
- import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
5
-
6
- /**
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @typedef {import("../../index.ts").Invocable} Invocable
11
- *
12
- * @this {AsyncTree|null}
13
- * @param {Treelike} treelike
14
- * @param {Invocable} invocable
15
- */
16
- export default function withTree(treelike, invocable) {
17
- assertScopeIsDefined(this, "with");
18
- const tree = Tree.from(treelike);
19
- const fn = toFunction(invocable);
20
- const scope = new Scope(tree, this);
21
- return fn.call(scope);
22
- }