@promptbook/markdown-utils 0.85.0-1 → 0.85.0-11

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.
@@ -47,6 +47,7 @@ import { parseKeywords } from '../utils/normalization/parseKeywords';
47
47
  import { parseKeywordsFromString } from '../utils/normalization/parseKeywordsFromString';
48
48
  import { removeDiacritics } from '../utils/normalization/removeDiacritics';
49
49
  import { searchKeywords } from '../utils/normalization/searchKeywords';
50
+ import { suffixUrl } from '../utils/normalization/suffixUrl';
50
51
  import { titleToName } from '../utils/normalization/titleToName';
51
52
  import { spaceTrim } from '../utils/organization/spaceTrim';
52
53
  import { extractParameterNames } from '../utils/parameters/extractParameterNames';
@@ -128,6 +129,7 @@ export { parseKeywords };
128
129
  export { parseKeywordsFromString };
129
130
  export { removeDiacritics };
130
131
  export { searchKeywords };
132
+ export { suffixUrl };
131
133
  export { titleToName };
132
134
  export { spaceTrim };
133
135
  export { extractParameterNames };
@@ -8,7 +8,6 @@ import type { Command as Program } from 'commander';
8
8
  */
9
9
  export declare function $initializeAboutCommand(program: Program): void;
10
10
  /**
11
- * TODO: !!! Test this in `deno`
12
11
  * TODO: [🗽] Unite branding and make single place for it
13
12
  * Note: [💞] Ignore a discrepancy between file name and entity name
14
13
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -1,7 +1,7 @@
1
1
  import type { Observable } from 'rxjs';
2
2
  import { PartialDeep } from 'type-fest';
3
- import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
4
3
  import type { task_id } from '../types/typeAliases';
4
+ import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
5
5
  import type { AbstractTaskResult } from './AbstractTaskResult';
6
6
  import type { PipelineExecutorResult } from './PipelineExecutorResult';
7
7
  /**
@@ -30,7 +30,7 @@ export declare function createTask<TTaskResult extends AbstractTaskResult>(optio
30
30
  */
31
31
  export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
32
32
  readonly taskType: 'EXECUTION';
33
- readonly taskId: `execution-${task_id}`;
33
+ readonly taskId: `exec-${task_id}`;
34
34
  };
35
35
  /**
36
36
  * Represents a task that prepares a pipeline
@@ -38,7 +38,7 @@ export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
38
38
  */
39
39
  export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
40
40
  readonly taskType: 'PREPARATION';
41
- readonly taskId: `preparation-${task_id}`;
41
+ readonly taskId: `prep-${task_id}`;
42
42
  };
43
43
  /**
44
44
  * Base interface for all task types
@@ -62,6 +62,10 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
62
62
  * Gets an observable stream of partial task results
63
63
  */
64
64
  asObservable(): Observable<PartialDeep<TTaskResult>>;
65
+ /**
66
+ * Gets just the current value which is mutated during the task processing
67
+ */
68
+ currentValue: PartialDeep<TTaskResult>;
65
69
  };
66
70
  export type Task = ExecutionTask | PreparationTask;
67
71
  export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type fs from 'node:fs/promises';
2
+ import type fs from 'fs/promises';
3
3
  /**
4
4
  * Container for all the tools needed to manipulate with filesystem
5
5
  */
@@ -11,8 +11,7 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
13
13
  /**
14
- * TODO: !!!!!!! CORS and security
15
- * TODO: !!!!!!! Allow to pass tokem here
14
+ * TODO: !! Add CORS and security - probbably via `helmet`
16
15
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
17
16
  * TODO: Split this file into multiple functions - handler for each request
18
17
  * TODO: Maybe use `$exportJson`
@@ -0,0 +1,7 @@
1
+ import type { string_url } from '../../types/typeAliases';
2
+ /**
3
+ * Adds suffix to the URL
4
+ *
5
+ * @public exported from `@promptbook/utils`
6
+ */
7
+ export declare function suffixUrl(value: URL, suffix: `/${string}`): string_url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/markdown-utils",
3
- "version": "0.85.0-1",
3
+ "version": "0.85.0-11",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('node:path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'node:path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.hexEncoder, global.sha256, global.node_path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, hexEncoder, sha256, node_path, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-0';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-10';
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
@@ -2190,11 +2190,27 @@
2190
2190
  */
2191
2191
  function createTask(options) {
2192
2192
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2193
- var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2193
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
2194
2194
  var partialResultSubject = new rxjs.BehaviorSubject({});
2195
2195
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2196
2196
  partialResultSubject.next(newOngoingResult);
2197
2197
  });
2198
+ finalResultPromise
2199
+ .catch(function (error) {
2200
+ partialResultSubject.error(error);
2201
+ })
2202
+ .then(function (value) {
2203
+ if (value) {
2204
+ try {
2205
+ assertsTaskSuccessful(value);
2206
+ partialResultSubject.next(value);
2207
+ }
2208
+ catch (error) {
2209
+ partialResultSubject.error(error);
2210
+ }
2211
+ }
2212
+ partialResultSubject.complete();
2213
+ });
2198
2214
  function asPromise(options) {
2199
2215
  return __awaiter(this, void 0, void 0, function () {
2200
2216
  var _a, isCrashedOnError, finalResult;
@@ -2218,9 +2234,10 @@
2218
2234
  taskId: taskId,
2219
2235
  asPromise: asPromise,
2220
2236
  asObservable: function () {
2221
- return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2222
- isCrashedOnError: true,
2223
- })));
2237
+ return partialResultSubject.asObservable();
2238
+ },
2239
+ get currentValue() {
2240
+ return partialResultSubject.value;
2224
2241
  },
2225
2242
  };
2226
2243
  }
@@ -3650,7 +3667,7 @@
3650
3667
  value = value.replace(/\.html$/, '');
3651
3668
  }
3652
3669
  else if (isValidFilePath(value)) {
3653
- value = node_path.basename(value);
3670
+ value = path.basename(value);
3654
3671
  // Note: Keeping extension in the name
3655
3672
  }
3656
3673
  value = value.split('/').join('-');
@@ -3756,9 +3773,9 @@
3756
3773
  }
3757
3774
  basename = url.split('/').pop() || titleToName(url);
3758
3775
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
3759
- rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3760
- filepath = node_path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
3761
- return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
3776
+ rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3777
+ filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
3778
+ return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
3762
3779
  case 2:
3763
3780
  _h.sent();
3764
3781
  _g = (_f = Buffer).from;
@@ -3768,7 +3785,7 @@
3768
3785
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3769
3786
  throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
3770
3787
  }
3771
- return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
3788
+ return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
3772
3789
  case 4:
3773
3790
  _h.sent();
3774
3791
  // TODO: [💵] Check the file security
@@ -3784,7 +3801,7 @@
3784
3801
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
3785
3802
  // <- TODO: [🧠] What is the best error type here`
3786
3803
  }
3787
- filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3804
+ filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3788
3805
  fileExtension = getFileExtension(filename_1);
3789
3806
  mimeType = extensionToMimeType(fileExtension || '');
3790
3807
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];