@promptbook/legacy-documents 0.81.0-11 → 0.81.0-13

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,4 +1,4 @@
1
1
  import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
2
- import { getBookTemplate } from '../other/templates/getBookTemplate';
2
+ import { getBookTemplates } from '../other/templates/getBookTemplates';
3
3
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
4
- export { getBookTemplate };
4
+ export { getBookTemplates };
@@ -68,6 +68,7 @@ import { trimCodeBlock } from '../utils/trimCodeBlock';
68
68
  import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
69
69
  import { unwrapResult } from '../utils/unwrapResult';
70
70
  import { isValidEmail } from '../utils/validators/email/isValidEmail';
71
+ import { isPathRoot } from '../utils/validators/filePath/isPathRoot';
71
72
  import { isValidFilePath } from '../utils/validators/filePath/isValidFilePath';
72
73
  import { isValidJavascriptName } from '../utils/validators/javascriptName/isValidJavascriptName';
73
74
  import { isValidPromptbookVersion } from '../utils/validators/semanticVersion/isValidPromptbookVersion';
@@ -147,6 +148,7 @@ export { trimCodeBlock };
147
148
  export { trimEndOfCodeBlock };
148
149
  export { unwrapResult };
149
150
  export { isValidEmail };
151
+ export { isPathRoot };
150
152
  export { isValidFilePath };
151
153
  export { isValidJavascriptName };
152
154
  export { isValidPromptbookVersion };
@@ -1,4 +1,3 @@
1
- import type { PipelineCollection } from '../../collection/PipelineCollection';
2
1
  import type { string_formfactor_name } from '../../formfactors/_common/string_formfactor_name';
3
2
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
4
3
  /**
@@ -7,15 +6,16 @@ import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
7
6
  * @singleton
8
7
  * @private internal cache of `getBookTemplate`
9
8
  */
10
- export declare let templatesPipelineCollection: PipelineCollection | null;
9
+ export declare let pipelines: Array<PipelineJson> | null;
11
10
  /**
12
11
  * Get template for new book
13
12
  *
13
+ * @param formfactorName - optional filter for FORMFACTOR - get only pipelines for this formfactor
14
+ * @returns list of pipelines
14
15
  * @public exported from `@promptbook/templates`
15
16
  */
16
- export declare function getBookTemplate(formfactorName: string_formfactor_name): PipelineJson;
17
+ export declare function getBookTemplates(formfactorName?: string_formfactor_name): ReadonlyArray<PipelineJson>;
17
18
  /**
18
- * TODO: !!!!!! Test
19
+ * TODO: Unit test
19
20
  * TODO: [🧠] Which is the best place for this function
20
- * TODO: !!!!!! `book string template notation
21
21
  */
@@ -5,3 +5,6 @@ import type { PromptbookFetch } from '../../../execution/PromptbookFetch';
5
5
  * @private as default `fetch` function used in Promptbook scrapers
6
6
  */
7
7
  export declare const scraperFetch: PromptbookFetch;
8
+ /**
9
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
10
+ */
@@ -9,5 +9,6 @@ import type { really_any } from '../../../utils/organization/really_any';
9
9
  */
10
10
  export declare function preserve(func: (...params: ReadonlyArray<really_any>) => unknown): void;
11
11
  /**
12
+ * TODO: Probbably remove in favour of `keepImported`
12
13
  * TODO: !! [1] This maybe does memory leak
13
14
  */
@@ -0,0 +1,12 @@
1
+ import type { string_dirname } from '../../../types/typeAliases';
2
+ import type { string_filename } from '../../../types/typeAliases';
3
+ /**
4
+ * Determines if the given path is a root path.
5
+ *
6
+ * Note: This does not check if the file exists only if the path is valid
7
+ * @public exported from `@promptbook/utils`
8
+ */
9
+ export declare function isPathRoot(value: string_dirname | string_filename): boolean;
10
+ /**
11
+ * TODO: [🍏] Make for MacOS paths
12
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🍏] Make for MacOS paths
4
+ */
@@ -7,3 +7,6 @@ import type { really_unknown } from '../../organization/really_unknown';
7
7
  * @public exported from `@promptbook/utils`
8
8
  */
9
9
  export declare function isValidFilePath(filename: really_unknown): filename is string_filename;
10
+ /**
11
+ * TODO: [🍏] Implement for MacOs
12
+ */
@@ -0,0 +1,16 @@
1
+ import type { ExecutionTools } from '../execution/ExecutionTools';
2
+ import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
3
+ import type { PipelineString } from '../pipeline/PipelineString';
4
+ import type { PrepareAndScrapeOptions } from '../prepare/PrepareAndScrapeOptions';
5
+ import type { string_filename } from '../types/typeAliases';
6
+ import type { string_pipeline_url } from '../types/typeAliases';
7
+ /**
8
+ * @see ./wizzard.ts `getPipeline` method
9
+ *
10
+ * @private usable through `ptbk run` and `@prompbook/wizzard`
11
+ */
12
+ export declare function $getCompiledBook(tools: Required<Pick<ExecutionTools, 'fs' | 'fetch'>>, pipelineSource: string_filename | string_pipeline_url | PipelineString, options?: PrepareAndScrapeOptions): Promise<PipelineJson>;
13
+ /**
14
+ * TODO: Write unit test
15
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
16
+ */
@@ -1,7 +1,7 @@
1
1
  import { Promisable } from 'type-fest';
2
- import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
3
2
  import type { ExecutionTools } from '../execution/ExecutionTools';
4
3
  import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
4
+ import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
5
5
  import type { PipelineString } from '../pipeline/PipelineString';
6
6
  import type { TaskProgress } from '../types/TaskProgress';
7
7
  import type { InputParameters } from '../types/typeAliases';
@@ -23,7 +23,7 @@ declare class Wizzard {
23
23
  *
24
24
  * @param pipelineSource
25
25
  */
26
- getExecutionTools(): Promise<ExecutionTools>;
26
+ getExecutionTools(): Promise<Required<Pick<ExecutionTools, 'fs' | 'fetch'>>>;
27
27
  /**
28
28
  * TODO: Make standalone function from this exported from node and used here and in `ptbk run`
29
29
  * @@@!!!
@@ -34,7 +34,7 @@ declare class Wizzard {
34
34
  *
35
35
  * @param pipelineSource
36
36
  */
37
- getPipeline(pipelineSource: string_filename | string_pipeline_url | PipelineString): Promise<PipelineJson>;
37
+ getCompiledBook(pipelineSource: string_filename | string_pipeline_url | PipelineString): Promise<PipelineJson>;
38
38
  }
39
39
  /**
40
40
  * 🧙‍♂️ @@@
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/legacy-documents",
3
- "version": "0.81.0-11",
3
+ "version": "0.81.0-13",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
@@ -54,7 +54,7 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/legacy-documents.index.d.ts",
56
56
  "peerDependencies": {
57
- "@promptbook/core": "0.81.0-11"
57
+ "@promptbook/core": "0.81.0-13"
58
58
  },
59
59
  "dependencies": {
60
60
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-10';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-12';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -945,21 +945,44 @@
945
945
  if (typeof filename !== 'string') {
946
946
  return false;
947
947
  }
948
+ if (filename.split('\n').length > 1) {
949
+ return false;
950
+ }
951
+ if (filename.split(' ').length >
952
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
953
+ return false;
954
+ }
948
955
  var filenameSlashes = filename.split('\\').join('/');
949
956
  // Absolute Unix path: /hello.txt
950
957
  if (/^(\/)/i.test(filenameSlashes)) {
958
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
951
959
  return true;
952
960
  }
953
961
  // Absolute Windows path: /hello.txt
954
962
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
963
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
955
964
  return true;
956
965
  }
957
966
  // Relative path: ./hello.txt
958
967
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
968
+ // console.log(filename, 'Relative path: ./hello.txt');
969
+ return true;
970
+ }
971
+ // Allow paths like foo/hello
972
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
973
+ // console.log(filename, 'Allow paths like foo/hello');
974
+ return true;
975
+ }
976
+ // Allow paths like hello.book
977
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
978
+ // console.log(filename, 'Allow paths like hello.book');
959
979
  return true;
960
980
  }
961
981
  return false;
962
982
  }
983
+ /**
984
+ * TODO: [🍏] Implement for MacOs
985
+ */
963
986
 
964
987
  /**
965
988
  * Tests if given string is valid URL.
@@ -1477,7 +1500,7 @@
1477
1500
  if (!(error instanceof Error)) {
1478
1501
  throw error;
1479
1502
  }
1480
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1503
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1481
1504
  }
1482
1505
  /*
1483
1506
  TODO: [0] Is there some more elegant way to check circular references?
@@ -3618,6 +3641,9 @@
3618
3641
  }
3619
3642
  });
3620
3643
  }); };
3644
+ /**
3645
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3646
+ */
3621
3647
 
3622
3648
  /**
3623
3649
  * @@@
@@ -3685,7 +3711,7 @@
3685
3711
  },
3686
3712
  }];
3687
3713
  case 2:
3688
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3714
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3689
3715
  if (tools.fs === undefined) {
3690
3716
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3691
3717
  // <- TODO: [🧠] What is the best error type here`
@@ -3700,7 +3726,7 @@
3700
3726
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3701
3727
  case 3:
3702
3728
  if (!(_f.sent())) {
3703
- throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
3729
+ throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
3704
3730
  }
3705
3731
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3706
3732
  return [2 /*return*/, {
@@ -4108,7 +4134,7 @@
4108
4134
  if (!(error instanceof Error)) {
4109
4135
  throw error;
4110
4136
  }
4111
- throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
4137
+ throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
4112
4138
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
4113
4139
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
4114
4140
  }