@promptbook/legacy-documents 0.78.0-0 → 0.78.3

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.
@@ -5,6 +5,8 @@ import { createCollectionFromPromise } from '../collection/constructors/createCo
5
5
  import { createCollectionFromUrl } from '../collection/constructors/createCollectionFromUrl';
6
6
  import { createSubcollection } from '../collection/constructors/createSubcollection';
7
7
  import { NAME } from '../config';
8
+ import { ADMIN_EMAIL } from '../config';
9
+ import { ADMIN_GITHUB_NAME } from '../config';
8
10
  import { CLAIM } from '../config';
9
11
  import { LOGO_LIGHT_SRC } from '../config';
10
12
  import { LOGO_DARK_SRC } from '../config';
@@ -123,6 +125,8 @@ export { createCollectionFromPromise };
123
125
  export { createCollectionFromUrl };
124
126
  export { createSubcollection };
125
127
  export { NAME };
128
+ export { ADMIN_EMAIL };
129
+ export { ADMIN_GITHUB_NAME };
126
130
  export { CLAIM };
127
131
  export { LOGO_LIGHT_SRC };
128
132
  export { LOGO_DARK_SRC };
@@ -6,7 +6,6 @@ import type { PipelineHeadCommandParser } from '../commands/_common/types/Comman
6
6
  import type { PipelineTaskCommandParser } from '../commands/_common/types/CommandParser';
7
7
  import type { CommandParserInput } from '../commands/_common/types/CommandParser';
8
8
  import type { CommandType } from '../commands/_common/types/CommandType';
9
- import type { CommandTypeOrAlias } from '../commands/_common/types/CommandType';
10
9
  import type { CommandUsagePlace } from '../commands/_common/types/CommandUsagePlaces';
11
10
  import type { ExpectCommand } from '../commands/EXPECT/ExpectCommand';
12
11
  import type { ForeachJson } from '../commands/FOREACH/ForeachJson';
@@ -266,7 +265,6 @@ export type { PipelineHeadCommandParser };
266
265
  export type { PipelineTaskCommandParser };
267
266
  export type { CommandParserInput };
268
267
  export type { CommandType };
269
- export type { CommandTypeOrAlias };
270
268
  export type { CommandUsagePlace };
271
269
  export type { ExpectCommand };
272
270
  export type { ForeachJson };
@@ -12,6 +12,6 @@ export type CommandType = Command['type'];
12
12
  *
13
13
  * This is a type of the command like "KNOWLEDGE" or "PERSONA"
14
14
  *
15
- export type CommandTypeOrAlias = Command['type'] | Command['aliasNames'] | Command['deprecatedNames'];
15
+ ex--rt type CommandTypeOrAlias = Command['type'] | Command['aliasNames'] | Command['deprecatedNames'];
16
16
  // <- TODO: [🧘] Implement
17
17
  */
@@ -1,5 +1,7 @@
1
1
  import type { CsvSettings } from './formats/csv/CsvSettings';
2
2
  import type { IntermediateFilesStrategy } from './types/IntermediateFilesStrategy';
3
+ import type { string_email } from './types/typeAliases';
4
+ import type { string_name } from './types/typeAliases';
3
5
  import type { string_url_image } from './types/typeAliases';
4
6
  /**
5
7
  * Warning message for the generated sections and files files
@@ -15,6 +17,18 @@ export declare const GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has be
15
17
  * @public exported from `@promptbook/core`
16
18
  */
17
19
  export declare const NAME = "Promptbook";
20
+ /**
21
+ * Email of the responsible person
22
+ *
23
+ * @public exported from `@promptbook/core`
24
+ */
25
+ export declare const ADMIN_EMAIL: string_email;
26
+ /**
27
+ * Name of the responsible person for the Promptbook on GitHub
28
+ *
29
+ * @public exported from `@promptbook/core`
30
+ */
31
+ export declare const ADMIN_GITHUB_NAME: string_name;
18
32
  /**
19
33
  * Claim for the Promptbook
20
34
  *
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Make error report URL for the given error
3
+ *
4
+ * @private !!!!!!
5
+ */
6
+ export declare function getErrorReportUrl(error: Error): URL;
@@ -12,5 +12,5 @@ export type ExecutionReportString = string & {
12
12
  readonly _type: 'ExecutionReportString';
13
13
  };
14
14
  /**
15
- * TODO: Better validation or remove branded type and make it just string
15
+ * TODO: [💩] Better validation or remove branded type and make it just string
16
16
  */
@@ -24,7 +24,7 @@ export declare const OPENAI_MODELS: ReadonlyArray<AvailableModel & {
24
24
  * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
25
25
  * @see https://openai.com/api/pricing/
26
26
  * @see /other/playground/playground.ts
27
- * TODO: [🍓] Make better
27
+ * TODO: [🍓][💩] Make better
28
28
  * TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
29
29
  * TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8,5 +8,5 @@ export type PipelineString = string & {
8
8
  readonly _type: 'Promptbook';
9
9
  };
10
10
  /**
11
- * TODO: !! Better validation (validatePipelineString) or remove branded type and make it just string
11
+ * TODO: [💩] Better validation (validatePipelineString) or remove branded type and make it just string
12
12
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/legacy-documents",
3
- "version": "0.78.0-0",
3
+ "version": "0.78.3",
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.78.0-0"
57
+ "@promptbook/core": "0.78.3"
58
58
  },
59
59
  "dependencies": {
60
60
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  *
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.78.2';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -169,198 +169,25 @@
169
169
  }
170
170
 
171
171
  /**
172
- * @@@
172
+ * Name for the Promptbook
173
173
  *
174
- * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
175
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
176
- *
177
- * @returns The same object as the input, but deeply frozen
178
- * @public exported from `@promptbook/utils`
179
- */
180
- function $deepFreeze(objectValue) {
181
- var e_1, _a;
182
- var propertyNames = Object.getOwnPropertyNames(objectValue);
183
- try {
184
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
185
- var propertyName = propertyNames_1_1.value;
186
- var value = objectValue[propertyName];
187
- if (value && typeof value === 'object') {
188
- $deepFreeze(value);
189
- }
190
- }
191
- }
192
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
193
- finally {
194
- try {
195
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
196
- }
197
- finally { if (e_1) throw e_1.error; }
198
- }
199
- return Object.freeze(objectValue);
200
- }
201
- /**
202
- * TODO: [🧠] Is there a way how to meaningfully test this utility
203
- */
204
-
205
- /**
206
- * This error type indicates that the error should not happen and its last check before crashing with some other error
174
+ * TODO: [🗽] Unite branding and make single place for it
207
175
  *
208
176
  * @public exported from `@promptbook/core`
209
177
  */
210
- var UnexpectedError = /** @class */ (function (_super) {
211
- __extends(UnexpectedError, _super);
212
- function UnexpectedError(message) {
213
- var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
214
- _this.name = 'UnexpectedError';
215
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
216
- return _this;
217
- }
218
- return UnexpectedError;
219
- }(Error));
220
-
178
+ var NAME = "Promptbook";
221
179
  /**
222
- * Checks if the value is [🚉] serializable as JSON
223
- * If not, throws an UnexpectedError with a rich error message and tracking
180
+ * Email of the responsible person
224
181
  *
225
- * - Almost all primitives are serializable BUT:
226
- * - `undefined` is not serializable
227
- * - `NaN` is not serializable
228
- * - Objects and arrays are serializable if all their properties are serializable
229
- * - Functions are not serializable
230
- * - Circular references are not serializable
231
- * - `Date` objects are not serializable
232
- * - `Map` and `Set` objects are not serializable
233
- * - `RegExp` objects are not serializable
234
- * - `Error` objects are not serializable
235
- * - `Symbol` objects are not serializable
236
- * - And much more...
237
- *
238
- * @throws UnexpectedError if the value is not serializable as JSON
239
- * @public exported from `@promptbook/utils`
240
- */
241
- function checkSerializableAsJson(name, value) {
242
- var e_1, _a;
243
- if (value === undefined) {
244
- throw new UnexpectedError("".concat(name, " is undefined"));
245
- }
246
- else if (value === null) {
247
- return;
248
- }
249
- else if (typeof value === 'boolean') {
250
- return;
251
- }
252
- else if (typeof value === 'number' && !isNaN(value)) {
253
- return;
254
- }
255
- else if (typeof value === 'string') {
256
- return;
257
- }
258
- else if (typeof value === 'symbol') {
259
- throw new UnexpectedError("".concat(name, " is symbol"));
260
- }
261
- else if (typeof value === 'function') {
262
- throw new UnexpectedError("".concat(name, " is function"));
263
- }
264
- else if (typeof value === 'object' && Array.isArray(value)) {
265
- for (var i = 0; i < value.length; i++) {
266
- checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
267
- }
268
- }
269
- else if (typeof value === 'object') {
270
- if (value instanceof Date) {
271
- throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
272
- }
273
- else if (value instanceof Map) {
274
- throw new UnexpectedError("".concat(name, " is Map"));
275
- }
276
- else if (value instanceof Set) {
277
- throw new UnexpectedError("".concat(name, " is Set"));
278
- }
279
- else if (value instanceof RegExp) {
280
- throw new UnexpectedError("".concat(name, " is RegExp"));
281
- }
282
- else if (value instanceof Error) {
283
- throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
284
- }
285
- else {
286
- try {
287
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
288
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
289
- if (subValue === undefined) {
290
- // Note: undefined in object is serializable - it is just omited
291
- continue;
292
- }
293
- checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
294
- }
295
- }
296
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
297
- finally {
298
- try {
299
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
300
- }
301
- finally { if (e_1) throw e_1.error; }
302
- }
303
- try {
304
- JSON.stringify(value); // <- TODO: [0]
305
- }
306
- catch (error) {
307
- if (!(error instanceof Error)) {
308
- throw error;
309
- }
310
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
311
- }
312
- /*
313
- TODO: [0] Is there some more elegant way to check circular references?
314
- const seen = new Set();
315
- const stack = [{ value }];
316
- while (stack.length > 0) {
317
- const { value } = stack.pop()!;
318
- if (typeof value === 'object' && value !== null) {
319
- if (seen.has(value)) {
320
- throw new UnexpectedError(`${name} has circular reference`);
321
- }
322
- seen.add(value);
323
- if (Array.isArray(value)) {
324
- stack.push(...value.map((value) => ({ value })));
325
- } else {
326
- stack.push(...Object.values(value).map((value) => ({ value })));
327
- }
328
- }
329
- }
330
- */
331
- return;
332
- }
333
- }
334
- else {
335
- throw new UnexpectedError("".concat(name, " is unknown"));
336
- }
337
- }
338
- /**
339
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
340
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
341
- * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
182
+ * @public exported from `@promptbook/core`
342
183
  */
343
-
184
+ var ADMIN_EMAIL = 'me@pavolhejny.com';
344
185
  /**
345
- * @@@
346
- * @@@
347
- *
348
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
186
+ * Name of the responsible person for the Promptbook on GitHub
349
187
  *
350
- * @param name - Name of the object for debugging purposes
351
- * @param objectValue - Object to be deeply frozen
352
- * @returns The same object as the input, but deeply frozen
353
- * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
354
- */
355
- function $asDeeplyFrozenSerializableJson(name, objectValue) {
356
- checkSerializableAsJson(name, objectValue);
357
- return $deepFreeze(objectValue);
358
- }
359
- /**
360
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
361
- * TODO: [🧠] Is there a way how to meaningfully test this utility
188
+ * @public exported from `@promptbook/core`
362
189
  */
363
-
190
+ var ADMIN_GITHUB_NAME = 'hejny';
364
191
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
365
192
  /**
366
193
  * The maximum number of iterations for a loops
@@ -412,7 +239,8 @@
412
239
  *
413
240
  * @public exported from `@promptbook/core`
414
241
  */
415
- var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
242
+ var RESERVED_PARAMETER_NAMES =
243
+ /* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
416
244
  'content',
417
245
  'context',
418
246
  'knowledge',
@@ -422,7 +250,7 @@
422
250
  // <- TODO: list here all command names
423
251
  // <- TODO: Add more like 'date', 'modelName',...
424
252
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
425
- ]);
253
+ ];
426
254
  /**
427
255
  * @@@
428
256
  *
@@ -522,6 +350,40 @@
522
350
  return MissingToolsError;
523
351
  }(Error));
524
352
 
353
+ /**
354
+ * Make error report URL for the given error
355
+ *
356
+ * @private !!!!!!
357
+ */
358
+ function getErrorReportUrl(error) {
359
+ var report = {
360
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
361
+ body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
362
+ };
363
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
364
+ reportUrl.searchParams.set('labels', 'bug');
365
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
366
+ reportUrl.searchParams.set('title', report.title);
367
+ reportUrl.searchParams.set('body', report.body);
368
+ return reportUrl;
369
+ }
370
+
371
+ /**
372
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
373
+ *
374
+ * @public exported from `@promptbook/core`
375
+ */
376
+ var UnexpectedError = /** @class */ (function (_super) {
377
+ __extends(UnexpectedError, _super);
378
+ function UnexpectedError(message) {
379
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
380
+ _this.name = 'UnexpectedError';
381
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
382
+ return _this;
383
+ }
384
+ return UnexpectedError;
385
+ }(Error));
386
+
525
387
  /**
526
388
  * Detects if the code is running in a Node.js environment
527
389
  *
@@ -1974,6 +1836,183 @@
1974
1836
  return parameterNames;
1975
1837
  }
1976
1838
 
1839
+ /**
1840
+ * @@@
1841
+ *
1842
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
1843
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1844
+ *
1845
+ * @returns The same object as the input, but deeply frozen
1846
+ * @public exported from `@promptbook/utils`
1847
+ */
1848
+ function $deepFreeze(objectValue) {
1849
+ var e_1, _a;
1850
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
1851
+ try {
1852
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1853
+ var propertyName = propertyNames_1_1.value;
1854
+ var value = objectValue[propertyName];
1855
+ if (value && typeof value === 'object') {
1856
+ $deepFreeze(value);
1857
+ }
1858
+ }
1859
+ }
1860
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1861
+ finally {
1862
+ try {
1863
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1864
+ }
1865
+ finally { if (e_1) throw e_1.error; }
1866
+ }
1867
+ return Object.freeze(objectValue);
1868
+ }
1869
+ /**
1870
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1871
+ */
1872
+
1873
+ /**
1874
+ * Checks if the value is [🚉] serializable as JSON
1875
+ * If not, throws an UnexpectedError with a rich error message and tracking
1876
+ *
1877
+ * - Almost all primitives are serializable BUT:
1878
+ * - `undefined` is not serializable
1879
+ * - `NaN` is not serializable
1880
+ * - Objects and arrays are serializable if all their properties are serializable
1881
+ * - Functions are not serializable
1882
+ * - Circular references are not serializable
1883
+ * - `Date` objects are not serializable
1884
+ * - `Map` and `Set` objects are not serializable
1885
+ * - `RegExp` objects are not serializable
1886
+ * - `Error` objects are not serializable
1887
+ * - `Symbol` objects are not serializable
1888
+ * - And much more...
1889
+ *
1890
+ * @throws UnexpectedError if the value is not serializable as JSON
1891
+ * @public exported from `@promptbook/utils`
1892
+ */
1893
+ function checkSerializableAsJson(name, value) {
1894
+ var e_1, _a;
1895
+ if (value === undefined) {
1896
+ throw new UnexpectedError("".concat(name, " is undefined"));
1897
+ }
1898
+ else if (value === null) {
1899
+ return;
1900
+ }
1901
+ else if (typeof value === 'boolean') {
1902
+ return;
1903
+ }
1904
+ else if (typeof value === 'number' && !isNaN(value)) {
1905
+ return;
1906
+ }
1907
+ else if (typeof value === 'string') {
1908
+ return;
1909
+ }
1910
+ else if (typeof value === 'symbol') {
1911
+ throw new UnexpectedError("".concat(name, " is symbol"));
1912
+ }
1913
+ else if (typeof value === 'function') {
1914
+ throw new UnexpectedError("".concat(name, " is function"));
1915
+ }
1916
+ else if (typeof value === 'object' && Array.isArray(value)) {
1917
+ for (var i = 0; i < value.length; i++) {
1918
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
1919
+ }
1920
+ }
1921
+ else if (typeof value === 'object') {
1922
+ if (value instanceof Date) {
1923
+ throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
1924
+ }
1925
+ else if (value instanceof Map) {
1926
+ throw new UnexpectedError("".concat(name, " is Map"));
1927
+ }
1928
+ else if (value instanceof Set) {
1929
+ throw new UnexpectedError("".concat(name, " is Set"));
1930
+ }
1931
+ else if (value instanceof RegExp) {
1932
+ throw new UnexpectedError("".concat(name, " is RegExp"));
1933
+ }
1934
+ else if (value instanceof Error) {
1935
+ throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
1936
+ }
1937
+ else {
1938
+ try {
1939
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1940
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1941
+ if (subValue === undefined) {
1942
+ // Note: undefined in object is serializable - it is just omited
1943
+ continue;
1944
+ }
1945
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
1946
+ }
1947
+ }
1948
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1949
+ finally {
1950
+ try {
1951
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1952
+ }
1953
+ finally { if (e_1) throw e_1.error; }
1954
+ }
1955
+ try {
1956
+ JSON.stringify(value); // <- TODO: [0]
1957
+ }
1958
+ catch (error) {
1959
+ if (!(error instanceof Error)) {
1960
+ throw error;
1961
+ }
1962
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
1963
+ }
1964
+ /*
1965
+ TODO: [0] Is there some more elegant way to check circular references?
1966
+ const seen = new Set();
1967
+ const stack = [{ value }];
1968
+ while (stack.length > 0) {
1969
+ const { value } = stack.pop()!;
1970
+ if (typeof value === 'object' && value !== null) {
1971
+ if (seen.has(value)) {
1972
+ throw new UnexpectedError(`${name} has circular reference`);
1973
+ }
1974
+ seen.add(value);
1975
+ if (Array.isArray(value)) {
1976
+ stack.push(...value.map((value) => ({ value })));
1977
+ } else {
1978
+ stack.push(...Object.values(value).map((value) => ({ value })));
1979
+ }
1980
+ }
1981
+ }
1982
+ */
1983
+ return;
1984
+ }
1985
+ }
1986
+ else {
1987
+ throw new UnexpectedError("".concat(name, " is unknown"));
1988
+ }
1989
+ }
1990
+ /**
1991
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1992
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1993
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1994
+ */
1995
+
1996
+ /**
1997
+ * @@@
1998
+ * @@@
1999
+ *
2000
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
2001
+ *
2002
+ * @param name - Name of the object for debugging purposes
2003
+ * @param objectValue - Object to be deeply frozen
2004
+ * @returns The same object as the input, but deeply frozen
2005
+ * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
2006
+ */
2007
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
2008
+ checkSerializableAsJson(name, objectValue);
2009
+ return $deepFreeze(objectValue);
2010
+ }
2011
+ /**
2012
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
2013
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
2014
+ */
2015
+
1977
2016
  /**
1978
2017
  * Unprepare just strips the preparation data of the pipeline
1979
2018
  *
@@ -3844,6 +3883,7 @@
3844
3883
  */
3845
3884
  function extractVariablesFromScript(script) {
3846
3885
  var variables = new Set();
3886
+ var originalScript = script;
3847
3887
  script = "(()=>{".concat(script, "})()");
3848
3888
  try {
3849
3889
  for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
@@ -3854,20 +3894,32 @@
3854
3894
  if (!(error instanceof ReferenceError)) {
3855
3895
  throw error;
3856
3896
  }
3857
- var undefinedName = error.message.split(' ')[0];
3858
3897
  /*
3859
3898
  Note: Parsing the error
3899
+ 🌟 Most devices:
3860
3900
  [PipelineUrlError: thing is not defined]
3901
+
3902
+ 🍏 iPhone`s Safari:
3903
+ [PipelineUrlError: Can't find variable: thing]
3861
3904
  */
3862
- if (!undefinedName) {
3905
+ var variableName = undefined;
3906
+ if (error.message.startsWith("Can't")) {
3907
+ // 🍏 Case
3908
+ variableName = error.message.split(' ').pop();
3909
+ }
3910
+ else {
3911
+ // 🌟 Case
3912
+ variableName = error.message.split(' ').shift();
3913
+ }
3914
+ if (variableName === undefined) {
3863
3915
  throw error;
3864
3916
  }
3865
- if (script.includes(undefinedName + '(')) {
3866
- script = "const ".concat(undefinedName, " = ()=>'';") + script;
3917
+ if (script.includes(variableName + '(')) {
3918
+ script = "const ".concat(variableName, " = ()=>'';") + script;
3867
3919
  }
3868
3920
  else {
3869
- variables.add(undefinedName);
3870
- script = "const ".concat(undefinedName, " = '';") + script;
3921
+ variables.add(variableName);
3922
+ script = "const ".concat(variableName, " = '';") + script;
3871
3923
  }
3872
3924
  }
3873
3925
  }
@@ -3875,7 +3927,9 @@
3875
3927
  if (!(error instanceof Error)) {
3876
3928
  throw error;
3877
3929
  }
3878
- throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
3930
+ 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)
3931
+ .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
3932
+ .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
3879
3933
  }
3880
3934
  return variables;
3881
3935
  }