inferred-types 0.35.0 → 0.36.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.
Files changed (46) hide show
  1. package/README.md +2 -34
  2. package/dist/index.d.ts +1803 -1663
  3. package/dist/index.mjs +95 -26
  4. package/package.json +12 -11
  5. package/src/runtime/combinators/filter.ts +0 -1
  6. package/src/runtime/lists/asArray.ts +8 -4
  7. package/src/runtime/lists/createConverter.ts +62 -0
  8. package/src/runtime/lists/index.ts +1 -0
  9. package/src/runtime/literals/box.ts +41 -20
  10. package/src/runtime/literals/ensureLeading.ts +17 -0
  11. package/src/runtime/literals/ensureTrailing.ts +17 -0
  12. package/src/runtime/literals/index.ts +4 -2
  13. package/src/runtime/literals/pathJoin.ts +22 -7
  14. package/src/runtime/literals/{stripStarting.ts → stripLeading.ts} +4 -4
  15. package/src/runtime/literals/stripTrailing.ts +15 -0
  16. package/src/runtime/literals/wide.ts +13 -0
  17. package/src/runtime/type-checks/ifSameType.ts +20 -0
  18. package/src/runtime/type-checks/index.ts +1 -0
  19. package/src/runtime/type-checks/isBoolean.ts +2 -1
  20. package/src/runtime/type-checks/isFunction.ts +2 -4
  21. package/src/runtime/type-checks/isObject.ts +10 -2
  22. package/src/runtime/type-checks/isString.ts +1 -1
  23. package/src/runtime/type-checks/isUndefined.ts +8 -0
  24. package/src/types/alphabetic/EnsureLeading.ts +24 -0
  25. package/src/types/alphabetic/EnsureTrailing.ts +24 -0
  26. package/src/types/alphabetic/PathJoin.ts +43 -31
  27. package/src/types/alphabetic/{StripStarting.ts → StripLeading.ts} +1 -1
  28. package/src/types/alphabetic/{StripEnding.ts → StripTrailing.ts} +1 -1
  29. package/src/types/alphabetic/index.ts +4 -2
  30. package/src/types/boolean-logic/HasParameters.ts +21 -0
  31. package/src/types/boolean-logic/array.ts +2 -2
  32. package/src/types/boolean-logic/boolean.ts +1 -1
  33. package/src/types/boolean-logic/equivalency.ts +2 -2
  34. package/src/types/boolean-logic/index.ts +1 -0
  35. package/src/types/dictionary/props.ts +5 -0
  36. package/src/types/lists/ConvertAndMap.ts +151 -0
  37. package/src/types/type-conversion/Widen.ts +15 -0
  38. package/tests/boolean-logic/HasParameters.ts +29 -0
  39. package/tests/lists/asArray.test.ts +19 -1
  40. package/tests/literals/EnsureStripLeadingTrailing.test.ts +79 -0
  41. package/tests/literals/PathJoin.test.ts +44 -37
  42. package/tests/literals/box.test.ts +31 -23
  43. package/tests/runtime/if-is.spec.ts +66 -5
  44. package/tests/runtime/map-and-convert.test.ts +31 -0
  45. package/dist/index.js +0 -868
  46. package/src/runtime/literals/stripEnding.ts +0 -9
package/dist/index.js DELETED
@@ -1,868 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- Configurator: () => Configurator,
24
- DEFAULT_MANY_TO_ONE_MAPPING: () => DEFAULT_MANY_TO_ONE_MAPPING,
25
- DEFAULT_ONE_TO_MANY_MAPPING: () => DEFAULT_ONE_TO_MANY_MAPPING,
26
- DEFAULT_ONE_TO_ONE_MAPPING: () => DEFAULT_ONE_TO_ONE_MAPPING,
27
- ExplicitFunction: () => ExplicitFunction,
28
- FluentConfigurator: () => FluentConfigurator,
29
- MapCardinality: () => MapCardinality,
30
- and: () => and,
31
- api: () => api,
32
- arrayToKeyLookup: () => arrayToKeyLookup,
33
- arrayToObject: () => arrayToObject,
34
- asArray: () => asArray,
35
- box: () => box,
36
- condition: () => condition,
37
- createFnWithProps: () => createFnWithProps,
38
- defineProperties: () => defineProperties,
39
- defineType: () => defineType,
40
- dictArr: () => dictArr,
41
- dictToKv: () => dictToKv,
42
- dictionaryTransform: () => dictionaryTransform,
43
- entries: () => entries,
44
- filter: () => filter,
45
- filterDictArray: () => filterDictArray,
46
- fnWithProps: () => fnWithProps,
47
- groupBy: () => groupBy,
48
- idLiteral: () => idLiteral,
49
- idTypeGuard: () => idTypeGuard,
50
- identity: () => identity,
51
- ifArray: () => ifArray,
52
- ifArrayPartial: () => ifArrayPartial,
53
- ifBoolean: () => ifBoolean,
54
- ifFalse: () => ifFalse,
55
- ifNull: () => ifNull,
56
- ifNumber: () => ifNumber,
57
- ifString: () => ifString,
58
- ifTrue: () => ifTrue,
59
- ifUndefined: () => ifUndefined,
60
- isArray: () => isArray,
61
- isBoolean: () => isBoolean,
62
- isBox: () => isBox,
63
- isFalse: () => isFalse,
64
- isFunction: () => isFunction,
65
- isNotFilter: () => isNotFilter,
66
- isNull: () => isNull,
67
- isNumber: () => isNumber,
68
- isNumericFilter: () => isNumericFilter,
69
- isObject: () => isObject,
70
- isString: () => isString,
71
- isSymbol: () => isSymbol,
72
- isTrue: () => isTrue,
73
- isType: () => isType,
74
- isUndefined: () => isUndefined,
75
- keys: () => keys,
76
- kindLiteral: () => kindLiteral,
77
- kv: () => kv,
78
- kvToDict: () => kvToDict,
79
- literal: () => literal,
80
- mapTo: () => mapTo,
81
- mapToDict: () => mapToDict,
82
- mapToFn: () => mapToFn,
83
- mapValues: () => mapValues,
84
- nameLiteral: () => nameLiteral,
85
- not: () => not,
86
- or: () => or,
87
- readonlyFnWithProps: () => readonlyFnWithProps,
88
- ruleSet: () => ruleSet,
89
- strArrayToDict: () => strArrayToDict,
90
- stripEnding: () => stripEnding,
91
- stripStarting: () => stripStarting,
92
- type: () => type,
93
- typeApi: () => typeApi,
94
- unbox: () => unbox,
95
- withValue: () => withValue
96
- });
97
- module.exports = __toCommonJS(src_exports);
98
-
99
- // src/types/dictionary/MapTo.ts
100
- var MapCardinality = /* @__PURE__ */ ((MapCardinality2) => {
101
- MapCardinality2["OneToMany"] = "I -> O[]";
102
- MapCardinality2["OneToOne"] = "I -> O";
103
- MapCardinality2["ManyToOne"] = "I[] -> O";
104
- return MapCardinality2;
105
- })(MapCardinality || {});
106
-
107
- // src/runtime/keys.ts
108
- function keys(obj, ...without) {
109
- const v = without.length > 0 ? Object.keys(obj).filter((k) => !without.includes(k)) : Object.keys(obj);
110
- return v;
111
- }
112
-
113
- // src/runtime/createFnWithProps.ts
114
- function createFnWithProps(fn, props) {
115
- return (() => {
116
- let combined = fn;
117
- for (const prop of keys(props)) {
118
- combined[prop] = props[prop];
119
- }
120
- return combined;
121
- })();
122
- }
123
- function fnWithProps(fn, props) {
124
- let combined = fn;
125
- for (const prop of keys(props)) {
126
- combined[prop] = props[prop];
127
- }
128
- return combined;
129
- }
130
- function readonlyFnWithProps(fn, props) {
131
- let combined = fn;
132
- for (const prop of keys(props)) {
133
- combined[prop] = props[prop];
134
- }
135
- return combined;
136
- }
137
-
138
- // src/runtime/ruleset.ts
139
- function ruleSet(defn) {
140
- return defn;
141
- }
142
-
143
- // src/runtime/api/api.ts
144
- var api = (priv) => (pub) => {
145
- const surface = () => pub;
146
- surface.prototype.priv = () => priv;
147
- return surface;
148
- };
149
-
150
- // src/runtime/combinators/and.ts
151
- var and = (...ops) => {
152
- const fn = (...args) => {
153
- return [...ops].every((i) => i(...args));
154
- };
155
- return fn;
156
- };
157
-
158
- // src/runtime/combinators/or.ts
159
- function or(...conditions) {
160
- return conditions.some((v) => v === true) ? true : false;
161
- }
162
-
163
- // src/runtime/combinators/not.ts
164
- var not = (op) => {
165
- const fn = (...args) => {
166
- return !op(...args);
167
- };
168
- return fn;
169
- };
170
-
171
- // src/runtime/runtime/condition.ts
172
- var condition = (c, input) => {
173
- return c(input);
174
- };
175
-
176
- // src/runtime/type-checks/isArray.ts
177
- function isArray(i) {
178
- return Array.isArray(i) === true;
179
- }
180
- function ifArray(val, isAnArray, isNotAnArray) {
181
- return isArray(val) ? isAnArray(val) : isNotAnArray(val);
182
- }
183
- function ifArrayPartial() {
184
- return (isAnArray, isNotAnArray) => {
185
- return (val) => ifArray(val, isAnArray, isNotAnArray);
186
- };
187
- }
188
-
189
- // src/runtime/type-checks/isBoolean.ts
190
- function isBoolean(i) {
191
- return typeof i === "boolean";
192
- }
193
- function ifBoolean(val, ifVal, elseVal) {
194
- return isBoolean(val) ? ifVal : elseVal;
195
- }
196
-
197
- // src/runtime/type-checks/isFalse.ts
198
- function isFalse(i) {
199
- return typeof i === "boolean" && !i;
200
- }
201
- function ifFalse(val, ifVal, elseVal) {
202
- return isFalse(val) ? ifVal : elseVal;
203
- }
204
-
205
- // src/runtime/type-checks/isFunction.ts
206
- function isFunction(input) {
207
- return typeof input === "function" ? true : false;
208
- }
209
-
210
- // src/runtime/type-checks/isNull.ts
211
- function isNull(i) {
212
- return i === null;
213
- }
214
- function ifNull(val, ifVal, elseVal) {
215
- return isNull(val) ? ifVal : elseVal;
216
- }
217
-
218
- // src/runtime/type-checks/isNumber.ts
219
- function isNumber(i) {
220
- return typeof i === "number";
221
- }
222
- function ifNumber(val, ifVal, elseVal) {
223
- return isNumber(val) ? ifVal : elseVal;
224
- }
225
-
226
- // src/runtime/type-checks/isObject.ts
227
- function isObject(i) {
228
- return typeof i === "object" && i !== null && Array.isArray(i) === false;
229
- }
230
-
231
- // src/runtime/type-checks/isString.ts
232
- function isString(i) {
233
- return typeof i === "string";
234
- }
235
- function ifString(val, ifVal, elseVal) {
236
- return isString(val) ? ifVal : elseVal;
237
- }
238
-
239
- // src/runtime/type-checks/isSymbol.ts
240
- function isSymbol(i) {
241
- return typeof i === "symbol";
242
- }
243
-
244
- // src/runtime/type-checks/isTrue.ts
245
- function isTrue(i) {
246
- return typeof i === "boolean" && i === true;
247
- }
248
- function ifTrue(val, ifVal, elseVal) {
249
- return isTrue(val) ? ifVal : elseVal;
250
- }
251
-
252
- // src/runtime/type-checks/isUndefined.ts
253
- function isUndefined(i) {
254
- return typeof i === "undefined";
255
- }
256
- function ifUndefined(val, ifVal, elseVal) {
257
- return isUndefined(val) ? ifVal : elseVal;
258
- }
259
-
260
- // src/runtime/runtime/type.ts
261
- var typeApi = () => ({
262
- string: {
263
- name: "string",
264
- type: "",
265
- typeGuard: (v) => isString(v),
266
- is: isString
267
- },
268
- boolean: {
269
- name: "boolean",
270
- type: true,
271
- typeGuard: (v) => isBoolean(v),
272
- is: isBoolean
273
- },
274
- number: {
275
- name: "number",
276
- type: 1,
277
- typeGuard: (v) => isNumber(v),
278
- is: isNumber
279
- },
280
- function: {
281
- name: "function",
282
- type: Function,
283
- typeGuard: (v) => isFunction(v),
284
- is: isFunction
285
- },
286
- null: {
287
- name: "null",
288
- type: null,
289
- typeGuard: (v) => isNull(v),
290
- is: isNull
291
- },
292
- symbol: {
293
- name: "symbol",
294
- type: Symbol(),
295
- typeGuard: (v) => isSymbol(v),
296
- is: isSymbol
297
- },
298
- undefined: {
299
- name: "undefined",
300
- type: void 0,
301
- typeGuard: (v) => isUndefined(v),
302
- is: isUndefined
303
- },
304
- true: {
305
- name: "true",
306
- type: true,
307
- typeGuard: (v) => isTrue(v),
308
- is: isTrue
309
- },
310
- false: {
311
- name: "false",
312
- type: false,
313
- typeGuard: (v) => isFalse(v),
314
- is: isFalse
315
- },
316
- object: {
317
- name: "object",
318
- type: {},
319
- typeGuard: (v) => isObject(v),
320
- is: isObject
321
- },
322
- array: {
323
- name: "array",
324
- type: {},
325
- typeGuard: (v) => isArray(v),
326
- is: isObject
327
- }
328
- });
329
- function isType(t) {
330
- return typeof t === "object" && ["name", "type", "is"].every((i) => Object.keys(t).includes(i));
331
- }
332
- function type(fn) {
333
- const result = fn(typeApi());
334
- if (!isType(result)) {
335
- throw new Error(
336
- `When using type(), the callback passed in returned an invalid type! Value returned was: ${result}`
337
- );
338
- }
339
- return result;
340
- }
341
-
342
- // src/runtime/dictionary/entries.ts
343
- function entries(obj) {
344
- const iterable = {
345
- *[Symbol.iterator]() {
346
- for (const k of keys(obj)) {
347
- yield [k, obj[k]];
348
- }
349
- }
350
- };
351
- return iterable;
352
- }
353
-
354
- // src/runtime/runtime/withValue.ts
355
- function withValue(td) {
356
- return (obj) => {
357
- const t = type(td);
358
- return Object.fromEntries(
359
- [...entries(obj)].filter(([_key, value]) => {
360
- return t.typeGuard(value);
361
- })
362
- );
363
- };
364
- }
365
-
366
- // src/runtime/lists/asArray.ts
367
- var asArray = (thing, _widen) => {
368
- return isArray(thing) ? thing : typeof thing === "undefined" ? [] : [thing];
369
- };
370
-
371
- // src/runtime/combinators/filter.ts
372
- function isNotFilter(f) {
373
- return typeof f === "object" && "not" in f;
374
- }
375
- function isNumericFilter(filter2) {
376
- return "equals" in filter2 || "notEqual" in filter2 || "greaterThan" in filter2 || "lessThan" in filter2 ? true : false;
377
- }
378
- var numericOps = (config, boolLogic) => {
379
- const equals = (n) => {
380
- const f = asArray(n);
381
- return f.length === 0 ? [] : [(input) => f.some((i) => i === input)];
382
- };
383
- const notEqual = (n) => {
384
- const f = asArray(n);
385
- return f.length === 0 ? [] : [(input) => f.every((i) => i !== input)];
386
- };
387
- const greaterThan = (n) => {
388
- const val = [(input) => input !== void 0 && input > n];
389
- return val;
390
- };
391
- const lessThan = (n) => {
392
- const val = [(input) => input !== void 0 && input < n];
393
- return val;
394
- };
395
- const conditions = [
396
- ..."equals" in config ? equals(config.equals) : [],
397
- ..."notEqual" in config ? notEqual(config.notEqual) : [],
398
- ..."greaterThan" in config ? greaterThan(config.greaterThan) : [],
399
- ..."lessThan" in config ? lessThan(config.lessThan) : []
400
- ];
401
- const combined = boolLogic === "AND" ? (input) => conditions.every((c) => c(input)) : (input) => conditions.some((c) => c(input));
402
- return combined;
403
- };
404
- var stringOps = (config, boolLogic) => {
405
- const startsWith = (n) => {
406
- const f = asArray(n);
407
- return f.length === 0 ? [] : [(input) => f.some((i) => input?.startsWith(i))];
408
- };
409
- const endsWith = (n) => {
410
- const f = asArray(n);
411
- return f.length === 0 ? [] : [(input) => f.some((i) => input?.endsWith(i))];
412
- };
413
- const contains = (n) => {
414
- const f = asArray(n);
415
- return f.length === 0 ? [] : [(input) => f.some((i) => input?.includes(i))];
416
- };
417
- const conditions = [
418
- ..."startsWith" in config ? startsWith(config.startsWith) : [],
419
- ..."endsWith" in config ? endsWith(config.endsWith) : [],
420
- ..."contains" in config ? contains(config.contains) : []
421
- ];
422
- const combined = boolLogic === "AND" ? (input) => conditions.every((c) => c(input)) : (input) => conditions.some((c) => c(input));
423
- return combined;
424
- };
425
- var filterFn = (defn, logicCombinator, ifUndefined2 = "no-impact") => {
426
- const config = isNotFilter(defn) ? defn["not"] : defn;
427
- const filter2 = (input) => {
428
- const undefValue = ifUndefined2 === "no-impact" ? logicCombinator === "AND" ? true : false : ifUndefined2;
429
- let flag;
430
- if (typeof input === "undefined") {
431
- flag = undefValue;
432
- } else if (isNumericFilter(config)) {
433
- const fn = numericOps(config, logicCombinator);
434
- flag = isNotFilter(defn) ? !fn(input) : fn(input);
435
- } else {
436
- const fn = stringOps(config, logicCombinator);
437
- flag = isNotFilter(defn) ? !fn(input) : fn(input);
438
- }
439
- return flag;
440
- };
441
- return filter2;
442
- };
443
- var filter = (config, logicCombinator = "AND", ifUndefined2 = "no-impact") => {
444
- return filterFn(config, logicCombinator, ifUndefined2);
445
- };
446
-
447
- // src/runtime/dictionary/arrayToKeyLookup.ts
448
- function arrayToKeyLookup(...keys2) {
449
- const obj = {};
450
- for (const key of keys2) {
451
- obj[key] = true;
452
- }
453
- return obj;
454
- }
455
-
456
- // src/runtime/dictionary/defineProperties.ts
457
- function defineProperties(obj) {
458
- return {
459
- ro(prop, errorMsg) {
460
- Object.defineProperty(obj, prop, {
461
- writable: false,
462
- set(v) {
463
- const message = errorMsg ? errorMsg(prop, v) : `The ${String(
464
- prop
465
- )} is readonly but an attempt was made to change it's value to "${JSON.stringify(
466
- v
467
- )}"!`;
468
- throw new Error(message);
469
- }
470
- });
471
- return obj;
472
- }
473
- };
474
- }
475
-
476
- // src/runtime/dictionary/dictionaryTransform.ts
477
- function dictionaryTransform(input, transform) {
478
- return keys(input).reduce((acc, i) => {
479
- const key = i;
480
- return { ...acc, [key]: transform(input, key) };
481
- }, {});
482
- }
483
-
484
- // src/runtime/dictionary/dictArr.ts
485
- var dictArr = (...dicts) => {
486
- const api2 = {
487
- length: dicts.length,
488
- toLookup: (prop) => {
489
- let dict = {};
490
- for (const obj of dicts) {
491
- const key = obj[prop];
492
- dict = { ...dict, [key]: obj };
493
- }
494
- return dict;
495
- },
496
- unique: (prop) => {
497
- const v = /* @__PURE__ */ new Set();
498
- dicts.forEach((i) => v.add(i[prop]));
499
- const size = dictArr(...dicts).count(prop);
500
- const values = Array.from(v);
501
- const u = {
502
- isUnique: values.includes(void 0) ? size === v.size - 1 : size === v.size,
503
- includedUndefined: values.includes(void 0) ? true : false,
504
- size,
505
- values
506
- };
507
- return u;
508
- },
509
- sum: (prop) => {
510
- return dicts.reduce((acc, obj) => prop in obj ? acc + obj[prop] : acc, 0);
511
- },
512
- count: (prop) => {
513
- return dicts.reduce(
514
- (acc, obj) => prop in obj && typeof obj[prop] !== "undefined" ? acc + 1 : acc,
515
- 0
516
- );
517
- }
518
- };
519
- return api2;
520
- };
521
-
522
- // src/runtime/dictionary/mapValues.ts
523
- function mapValues(obj, valueMapper) {
524
- return Object.fromEntries(
525
- [...entries(obj)].map(([k, v]) => [k, valueMapper(v)])
526
- );
527
- }
528
-
529
- // src/runtime/dictionary/mapTo.ts
530
- var toFinalizedConfig = (config) => {
531
- return { ...config, finalized: true };
532
- };
533
- var DEFAULT_ONE_TO_MANY_MAPPING = toFinalizedConfig({
534
- input: "req",
535
- output: "opt",
536
- cardinality: "I -> O[]"
537
- });
538
- var DEFAULT_ONE_TO_ONE_MAPPING = toFinalizedConfig({
539
- input: "req",
540
- output: "req",
541
- cardinality: "I -> O"
542
- });
543
- var DEFAULT_MANY_TO_ONE_MAPPING = toFinalizedConfig({
544
- input: "req",
545
- output: "req",
546
- cardinality: "I[] -> O"
547
- });
548
- var debugMsg = (config, source, output) => {
549
- if (config.debug) {
550
- console.error(
551
- `MapFn[${typeof config.output === "string" ? `${config.output}, ` : ""}${config.input}, ${config.cardinality}, ${config.output}] received:
552
-
553
- ${JSON.stringify(source)}
554
-
555
- And produced: ${JSON.stringify(
556
- output
557
- )}
558
-
559
- `
560
- );
561
- }
562
- };
563
- var mapper = (config) => (map) => {
564
- const fn = (source) => {
565
- const isArray2 = config.cardinality === "I -> O[]" && Array.isArray(source) ? true : config.cardinality === "I[] -> O" && Array.isArray(source) && Array.isArray(source[0]) ? true : false;
566
- if (isArray2) {
567
- const output = source.flatMap(map);
568
- debugMsg(config, source, output);
569
- return output;
570
- } else {
571
- const output = map(source);
572
- debugMsg(config, source, output);
573
- return output;
574
- }
575
- };
576
- return createFnWithProps(fn, {
577
- input: config.input,
578
- output: config.output,
579
- cardinality: config.cardinality,
580
- debug: config.debug,
581
- inputType: {},
582
- outputType: {},
583
- fnSignature: null
584
- });
585
- };
586
- var setMapper = (config = { input: void 0, output: void 0, cardinality: void 0 }, defaultValue) => ({
587
- map: (source) => {
588
- const c = {
589
- ...defaultValue,
590
- ...config
591
- };
592
- return mapper(c)(source);
593
- },
594
- input: config?.input || defaultValue.input,
595
- output: config?.output || defaultValue.output,
596
- cardinality: config?.cardinality || defaultValue.cardinality,
597
- debug: config?.debug || false
598
- });
599
- var mapToFn = (map) => {
600
- return mapper(DEFAULT_ONE_TO_MANY_MAPPING)(map);
601
- };
602
- var mapToDict = {
603
- config(config) {
604
- const c = { ...DEFAULT_ONE_TO_MANY_MAPPING, ...config };
605
- return setMapper(c, DEFAULT_ONE_TO_MANY_MAPPING);
606
- },
607
- oneToOne(config) {
608
- const c = { ...DEFAULT_ONE_TO_ONE_MAPPING, ...config };
609
- return setMapper(c, DEFAULT_ONE_TO_ONE_MAPPING);
610
- },
611
- manyToOne(config) {
612
- const c = { ...DEFAULT_MANY_TO_ONE_MAPPING, ...config };
613
- return setMapper(c, DEFAULT_MANY_TO_ONE_MAPPING);
614
- },
615
- oneToMany(config) {
616
- const c = { ...DEFAULT_ONE_TO_MANY_MAPPING, ...config };
617
- return setMapper(c, DEFAULT_ONE_TO_MANY_MAPPING);
618
- }
619
- };
620
- var mapTo = createFnWithProps(mapToFn, mapToDict);
621
-
622
- // src/runtime/dictionary/strArrayToDict.ts
623
- function strArrayToDict(...strings) {
624
- return strings.reduce((acc, str) => {
625
- acc = { ...acc, [str]: true };
626
- return acc;
627
- }, {});
628
- }
629
-
630
- // src/runtime/dictionary/kv/dictToKv.ts
631
- function dictToKv(obj, _makeTuple = false) {
632
- return keys(obj).map((k) => {
633
- return { key: k, value: obj[k] };
634
- });
635
- }
636
-
637
- // src/runtime/state/Configurator.ts
638
- function omit(obj, ...removals) {
639
- const untyped = removals;
640
- return Object.fromEntries(Object.entries(obj).filter(([key]) => !untyped.includes(key)));
641
- }
642
- function Configurator() {
643
- let configuration = () => ({});
644
- const api2 = () => {
645
- return {
646
- set(key, value) {
647
- const keyValue = { [key]: value };
648
- const config = configuration();
649
- const updated = { ...config, ...keyValue };
650
- configuration = () => updated;
651
- return updated;
652
- },
653
- remove(key) {
654
- const config = configuration();
655
- const updated = omit(config, key);
656
- configuration = () => updated;
657
- return updated;
658
- },
659
- done() {
660
- return configuration();
661
- }
662
- };
663
- };
664
- return api2();
665
- }
666
-
667
- // src/runtime/state/FluentConfigurator.ts
668
- function FluentConfigurator(initial = {}) {
669
- const api2 = (current) => {
670
- return {
671
- set(key, value) {
672
- const keyValue = { [key]: value };
673
- const updated = { ...keyValue, ...current };
674
- return api2(updated);
675
- },
676
- done() {
677
- return current;
678
- }
679
- };
680
- };
681
- if (initial && typeof initial !== "object") {
682
- throw new Error(
683
- "The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed."
684
- );
685
- }
686
- return initial ? api2(initial) : api2({});
687
- }
688
-
689
- // src/runtime/dictionary/kv/filterDictArray.ts
690
- function filterDictArray(dictArr2, cb) {
691
- const state = Configurator();
692
- const updated = dictArr2.filter((i) => {
693
- const [k, v] = i;
694
- const keep = cb(k, v);
695
- if (!keep) {
696
- state.set(k, true);
697
- }
698
- return keep;
699
- });
700
- return updated;
701
- }
702
-
703
- // src/runtime/dictionary/kv/kv.ts
704
- function kv(key, value) {
705
- return { [key]: value };
706
- }
707
-
708
- // src/runtime/dictionary/kv/kvToDict.ts
709
- function kvToDict(kvArr) {
710
- const out = {};
711
- for (const kv2 of kvArr) {
712
- out[kv2.key] = kv2.value;
713
- }
714
- return out;
715
- }
716
-
717
- // src/runtime/lists/groupBy.ts
718
- function groupBy(_data) {
719
- throw new Error("not implemented");
720
- }
721
-
722
- // src/runtime/literals/ExplicitFunction.ts
723
- function ExplicitFunction(fn) {
724
- return fn;
725
- }
726
-
727
- // src/runtime/literals/arrayToObject.ts
728
- function arrayToObject(prop, unique) {
729
- const transform = (arr) => {
730
- const result = unique !== false ? arr.reduce((acc, v) => ({ ...acc, [v[prop]]: v }), {}) : arr.reduce((acc, v) => {
731
- const existing = acc[v[prop]] || [];
732
- return { ...acc, [v[prop]]: [...existing, v] };
733
- }, {});
734
- return result;
735
- };
736
- return transform;
737
- }
738
-
739
- // src/runtime/literals/box.ts
740
- function box(value) {
741
- const rtn = {
742
- __kind: "box",
743
- value,
744
- unbox: () => value
745
- };
746
- return rtn;
747
- }
748
- function isBox(thing) {
749
- return typeof thing === "object" && "__kind" in thing && thing.__kind === "box";
750
- }
751
- function unbox(thing) {
752
- return isBox(thing) ? thing.unbox() : thing;
753
- }
754
-
755
- // src/runtime/literals/defineType.ts
756
- function defineType(literal2 = {}) {
757
- return (wide = {}) => {
758
- return literal2 ? { ...wide, ...literal2 } : wide;
759
- };
760
- }
761
-
762
- // src/runtime/literals/identity.ts
763
- var identity = (v) => v;
764
-
765
- // src/runtime/literals/literal.ts
766
- function idLiteral(o) {
767
- return { ...o, id: o.id };
768
- }
769
- function nameLiteral(o) {
770
- return o;
771
- }
772
- function kindLiteral(o) {
773
- return o;
774
- }
775
- function idTypeGuard(_o) {
776
- return true;
777
- }
778
- function literal(obj) {
779
- return obj;
780
- }
781
-
782
- // src/runtime/literals/stripEnding.ts
783
- function stripEnding(content, strip) {
784
- const re = new RegExp(`(.*)${strip}$`);
785
- return content.endsWith(strip) ? content.replace(re, "$1") : content;
786
- }
787
-
788
- // src/runtime/literals/stripStarting.ts
789
- function stripStarting(content, strip) {
790
- const re = new RegExp(`^${strip}(.*)`);
791
- return content.startsWith(strip) ? content.replace(re, "$1") : content;
792
- }
793
- // Annotate the CommonJS export names for ESM import in node:
794
- 0 && (module.exports = {
795
- Configurator,
796
- DEFAULT_MANY_TO_ONE_MAPPING,
797
- DEFAULT_ONE_TO_MANY_MAPPING,
798
- DEFAULT_ONE_TO_ONE_MAPPING,
799
- ExplicitFunction,
800
- FluentConfigurator,
801
- MapCardinality,
802
- and,
803
- api,
804
- arrayToKeyLookup,
805
- arrayToObject,
806
- asArray,
807
- box,
808
- condition,
809
- createFnWithProps,
810
- defineProperties,
811
- defineType,
812
- dictArr,
813
- dictToKv,
814
- dictionaryTransform,
815
- entries,
816
- filter,
817
- filterDictArray,
818
- fnWithProps,
819
- groupBy,
820
- idLiteral,
821
- idTypeGuard,
822
- identity,
823
- ifArray,
824
- ifArrayPartial,
825
- ifBoolean,
826
- ifFalse,
827
- ifNull,
828
- ifNumber,
829
- ifString,
830
- ifTrue,
831
- ifUndefined,
832
- isArray,
833
- isBoolean,
834
- isBox,
835
- isFalse,
836
- isFunction,
837
- isNotFilter,
838
- isNull,
839
- isNumber,
840
- isNumericFilter,
841
- isObject,
842
- isString,
843
- isSymbol,
844
- isTrue,
845
- isType,
846
- isUndefined,
847
- keys,
848
- kindLiteral,
849
- kv,
850
- kvToDict,
851
- literal,
852
- mapTo,
853
- mapToDict,
854
- mapToFn,
855
- mapValues,
856
- nameLiteral,
857
- not,
858
- or,
859
- readonlyFnWithProps,
860
- ruleSet,
861
- strArrayToDict,
862
- stripEnding,
863
- stripStarting,
864
- type,
865
- typeApi,
866
- unbox,
867
- withValue
868
- });