@promptbook/markdown-utils 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/markdown-utils",
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,
package/umd/index.umd.js CHANGED
@@ -24,7 +24,7 @@
24
24
  * @generated
25
25
  * @see https://github.com/webgptorg/promptbook
26
26
  */
27
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-10';
27
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-12';
28
28
  /**
29
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -927,7 +927,7 @@
927
927
  if (!(error instanceof Error)) {
928
928
  throw error;
929
929
  }
930
- 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 "); }));
930
+ 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 "); }));
931
931
  }
932
932
  /*
933
933
  TODO: [0] Is there some more elegant way to check circular references?
@@ -3482,21 +3482,44 @@
3482
3482
  if (typeof filename !== 'string') {
3483
3483
  return false;
3484
3484
  }
3485
+ if (filename.split('\n').length > 1) {
3486
+ return false;
3487
+ }
3488
+ if (filename.split(' ').length >
3489
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
3490
+ return false;
3491
+ }
3485
3492
  var filenameSlashes = filename.split('\\').join('/');
3486
3493
  // Absolute Unix path: /hello.txt
3487
3494
  if (/^(\/)/i.test(filenameSlashes)) {
3495
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
3488
3496
  return true;
3489
3497
  }
3490
3498
  // Absolute Windows path: /hello.txt
3491
3499
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
3500
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
3492
3501
  return true;
3493
3502
  }
3494
3503
  // Relative path: ./hello.txt
3495
3504
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
3505
+ // console.log(filename, 'Relative path: ./hello.txt');
3506
+ return true;
3507
+ }
3508
+ // Allow paths like foo/hello
3509
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
3510
+ // console.log(filename, 'Allow paths like foo/hello');
3511
+ return true;
3512
+ }
3513
+ // Allow paths like hello.book
3514
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
3515
+ // console.log(filename, 'Allow paths like hello.book');
3496
3516
  return true;
3497
3517
  }
3498
3518
  return false;
3499
3519
  }
3520
+ /**
3521
+ * TODO: [🍏] Implement for MacOs
3522
+ */
3500
3523
 
3501
3524
  /**
3502
3525
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -3521,6 +3544,9 @@
3521
3544
  }
3522
3545
  });
3523
3546
  }); };
3547
+ /**
3548
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3549
+ */
3524
3550
 
3525
3551
  /**
3526
3552
  * @@@
@@ -3588,7 +3614,7 @@
3588
3614
  },
3589
3615
  }];
3590
3616
  case 2:
3591
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3617
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3592
3618
  if (tools.fs === undefined) {
3593
3619
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3594
3620
  // <- TODO: [🧠] What is the best error type here`
@@ -3603,7 +3629,7 @@
3603
3629
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3604
3630
  case 3:
3605
3631
  if (!(_f.sent())) {
3606
- 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 "); }));
3632
+ 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 "); }));
3607
3633
  }
3608
3634
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3609
3635
  return [2 /*return*/, {
@@ -4011,7 +4037,7 @@
4011
4037
  if (!(error instanceof Error)) {
4012
4038
  throw error;
4013
4039
  }
4014
- 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)
4040
+ 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)
4015
4041
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
4016
4042
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
4017
4043
  }