insightfulpipe 0.4.2 → 0.5.0

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.
@@ -1,26 +1,41 @@
1
1
  import { fetchCatalog, fetchSkillFiles, getCatalogUrl, pageUrl, resolveSkill, skillKey } from './catalog.js';
2
2
  import { validateBundle } from './installer.js';
3
+ import { categoryFor, keyType } from './keys.js';
4
+ import { installNameFor, resolveWorkspaceSkill } from './names.js';
3
5
  import {
4
- fetchPrivateCatalog,
5
- fetchPrivateSkillFiles,
6
- privateSourceUrl,
7
- privateWorkspaceId,
8
- resolvePrivateSkill,
9
- validatePrivateBundle,
6
+ fetchWorkspaceCatalog,
7
+ fetchWorkspaceSkillFiles,
8
+ validateWorkspaceBundle,
9
+ workspaceIdFor,
10
+ workspaceSourceUrl,
10
11
  } from './private.js';
11
12
 
12
- /** Where skills come from: the public library on the website, with no key, or a workspace's private
13
- * skills from the app API, with the user's key. A command uses exactly one source and never falls back
14
- * to the other; an installed skill goes back to the source its marker names. */
13
+ /** Where skills come from: insightfulpipe.com with no key, or a workspace (its Public and Custom skills)
14
+ * from the app API with the user's key. A command uses exactly one source and never falls back to the
15
+ * other; an installed skill goes back to the source its marker names. */
15
16
 
16
17
  /** Markers written before 0.4.0 have no origin, and every one of those is public. */
17
18
  export function markerOrigin(marker) {
18
19
  return marker?.origin === 'private' ? 'private' : 'public';
19
20
  }
20
21
 
21
- /** A private marker's own category is never shown: it may have come with a cloned repository. */
22
+ /** A workspace marker's own category is never shown: it may have come with a cloned repository. The prefix
23
+ * comes from the key's form alone, a fixed word; nothing else the marker claims is shown. */
22
24
  export function markerLabel(marker) {
23
- return markerOrigin(marker) === 'private' ? `private/${marker.slug}` : `${marker.category}/${marker.slug}`;
25
+ return markerOrigin(marker) === 'private'
26
+ ? `${categoryFor(keyType(marker.key))}/${marker.slug}`
27
+ : `${marker.category}/${marker.slug}`;
28
+ }
29
+
30
+ /** `public` or `custom` for a workspace marker with a valid key, else null. */
31
+ export function markerType(marker) {
32
+ return markerOrigin(marker) === 'private' ? keyType(marker.key) : null;
33
+ }
34
+
35
+ /** What `list` calls a skill's origin: a Public workspace skill is never called private. */
36
+ export function listedOrigin(marker) {
37
+ if (markerOrigin(marker) === 'public') return 'public';
38
+ return markerType(marker) === 'public' ? 'workspace' : 'private';
24
39
  }
25
40
 
26
41
  function publicSource(catalog) {
@@ -28,6 +43,7 @@ function publicSource(catalog) {
28
43
  catalog.skills.filter((other) => other.slug === skill.slug).length > 1 ? skillKey(skill) : skill.slug;
29
44
  return {
30
45
  origin: 'public',
46
+ noFiles: 'The public source has no files for this skill.',
31
47
  skills: catalog.skills,
32
48
  resolve: (name) => resolveSkill(name, catalog.skills),
33
49
  find: (marker) => catalog.skills.find((skill) => skill.category === marker.category && skill.slug === marker.slug),
@@ -46,38 +62,50 @@ function publicSource(catalog) {
46
62
  };
47
63
  }
48
64
 
49
- function privateSourceFor(workspaceId, skills) {
50
- const installName = (skill) => (skills.filter((other) => other.slug === skill.slug).length > 1 ? skill.key : skill.slug);
65
+ /** `sourceName` is what the JSON calls the source: `private` when the user typed `--private`, as in 0.4. */
66
+ function workspaceSourceFor(workspaceId, skills, sourceName) {
67
+ const installName = (skill) => installNameFor(skill, skills);
51
68
  return {
52
69
  origin: 'private',
70
+ sourceName,
53
71
  workspaceId,
72
+ noFiles: `Workspace ${workspaceId} has no files for this skill.`,
54
73
  skills,
55
- resolve: (name) => resolvePrivateSkill(name, skills),
74
+ resolve: (name) => resolveWorkspaceSkill(name, skills, workspaceId),
56
75
  find: (marker) => skills.find((skill) => skill.key === marker.key),
57
- files: (skill) => fetchPrivateSkillFiles(workspaceId, skill.key),
58
- validate: validatePrivateBundle,
59
- installOptions: (skill) => ({ origin: 'private', source: privateSourceUrl(), key: skill.key, workspaceId }),
60
- summarize: (skill) => ({
61
- skill: skill.slug,
62
- key: skill.key,
63
- category: skill.category,
64
- name: skill.name,
65
- description: skill.description ?? '',
66
- data_source: skill.data_source || null,
67
- version: skill.version ?? null,
68
- install: `insightfulpipe skills install ${installName(skill)} --private --workspace ${workspaceId}`,
69
- page: null,
70
- }),
76
+ files: (skill) => fetchWorkspaceSkillFiles(workspaceId, skill.key),
77
+ validate: validateWorkspaceBundle,
78
+ installName,
79
+ installOptions: (skill) => ({ origin: 'private', source: workspaceSourceUrl(), key: skill.key, workspaceId }),
80
+ summarize: (skill) => summarizeWorkspaceSkill(skill, installName(skill), workspaceId),
81
+ };
82
+ }
83
+
84
+ function summarizeWorkspaceSkill(skill, name, workspaceId) {
85
+ return {
86
+ skill: skill.slug,
87
+ key: skill.key,
88
+ type: skill.type,
89
+ category: skill.category,
90
+ name: skill.name,
91
+ description: skill.description ?? '',
92
+ data_source: skill.data_source || null,
93
+ version: skill.version ?? null,
94
+ install: `insightfulpipe skills install ${name} --workspace ${workspaceId}`,
95
+ page: null,
71
96
  };
72
97
  }
73
98
 
74
- async function openPrivate(workspaceId) {
75
- return privateSourceFor(workspaceId, await fetchPrivateCatalog(workspaceId));
99
+ async function openWorkspace(workspaceId, sourceName = 'workspace') {
100
+ return workspaceSourceFor(workspaceId, await fetchWorkspaceCatalog(workspaceId), sourceName);
76
101
  }
77
102
 
78
- /** The source a command was asked for: `--private` (with `--workspace` or the saved scope), else public. */
103
+ /** The source a command was asked for: `--workspace`, or `--private` with it or the saved scope, else
104
+ * insightfulpipe.com. The saved scope alone never switches the source. */
79
105
  export async function openSource(opts) {
80
- return opts.private ? openPrivate(privateWorkspaceId(opts)) : publicSource(await fetchCatalog());
106
+ return opts.private || opts.workspace !== undefined
107
+ ? openWorkspace(workspaceIdFor(opts), opts.private ? 'private' : 'workspace')
108
+ : publicSource(await fetchCatalog());
81
109
  }
82
110
 
83
111
  function markerWorkspace(marker) {
@@ -89,8 +117,8 @@ function openForMarker(marker) {
89
117
  if (markerOrigin(marker) === 'public') return openSource({});
90
118
  const workspaceId = markerWorkspace(marker);
91
119
  return workspaceId
92
- ? openPrivate(workspaceId)
93
- : Promise.reject(new Error('Its marker names no workspace. Install it again with --private.'));
120
+ ? openWorkspace(workspaceId)
121
+ : Promise.reject(new Error('Its marker names no workspace. Install it again with --workspace <id>.'));
94
122
  }
95
123
 
96
124
  /** Opens each installed skill's own source once per command; a source that failed fails each of its skills. */