@jfdevelops/multi-step-form-core 1.0.0-alpha.17 → 1.0.0-alpha.19
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.
- package/dist/_internals.cjs +14 -0
- package/dist/_internals.d.cts +4 -0
- package/dist/_internals.d.mts +4 -0
- package/dist/_internals.mjs +5 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +16 -0
- package/dist/internals/step-schema.cjs +389 -0
- package/dist/internals/step-schema.cjs.map +1 -0
- package/dist/internals/step-schema.d.cts +41 -0
- package/dist/internals/step-schema.d.cts.map +1 -0
- package/dist/internals/step-schema.d.mts +41 -0
- package/dist/internals/step-schema.d.mts.map +1 -0
- package/dist/internals/step-schema.mjs +389 -0
- package/dist/internals/step-schema.mjs.map +1 -0
- package/dist/internals/utils.cjs +94 -0
- package/dist/internals/utils.cjs.map +1 -0
- package/dist/internals/utils.d.cts +27 -0
- package/dist/internals/utils.d.cts.map +1 -0
- package/dist/internals/utils.d.mts +27 -0
- package/dist/internals/utils.d.mts.map +1 -0
- package/dist/internals/utils.mjs +91 -0
- package/dist/internals/utils.mjs.map +1 -0
- package/dist/observable.cjs +44 -0
- package/dist/observable.cjs.map +1 -0
- package/dist/observable.d.cts +26 -0
- package/dist/observable.d.cts.map +1 -0
- package/dist/observable.d.mts +26 -0
- package/dist/observable.d.mts.map +1 -0
- package/dist/observable.mjs +44 -0
- package/dist/observable.mjs.map +1 -0
- package/dist/schema.cjs +68 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +28 -0
- package/dist/schema.d.cts.map +1 -0
- package/dist/schema.d.mts +28 -0
- package/dist/schema.d.mts.map +1 -0
- package/dist/schema.mjs +67 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/steps/fields.cjs +23 -0
- package/dist/steps/fields.cjs.map +1 -0
- package/dist/steps/fields.d.cts +18 -0
- package/dist/steps/fields.d.cts.map +1 -0
- package/dist/steps/fields.d.mts +18 -0
- package/dist/steps/fields.d.mts.map +1 -0
- package/dist/steps/fields.mjs +18 -0
- package/dist/steps/fields.mjs.map +1 -0
- package/dist/steps/index.cjs +4 -0
- package/dist/steps/index.mjs +6 -0
- package/dist/steps/schema.cjs +194 -0
- package/dist/steps/schema.cjs.map +1 -0
- package/dist/steps/schema.d.cts +124 -0
- package/dist/steps/schema.d.cts.map +1 -0
- package/dist/steps/schema.d.mts +124 -0
- package/dist/steps/schema.d.mts.map +1 -0
- package/dist/steps/schema.mjs +194 -0
- package/dist/steps/schema.mjs.map +1 -0
- package/dist/steps/types.cjs +33 -0
- package/dist/steps/types.cjs.map +1 -0
- package/dist/steps/types.d.cts +332 -0
- package/dist/steps/types.d.cts.map +1 -0
- package/dist/steps/types.d.mts +332 -0
- package/dist/steps/types.d.mts.map +1 -0
- package/dist/steps/types.mjs +27 -0
- package/dist/steps/types.mjs.map +1 -0
- package/dist/steps/utils.cjs +96 -0
- package/dist/steps/utils.cjs.map +1 -0
- package/dist/steps/utils.d.cts +10 -0
- package/dist/steps/utils.d.cts.map +1 -0
- package/dist/steps/utils.d.mts +10 -0
- package/dist/steps/utils.d.mts.map +1 -0
- package/dist/steps/utils.mjs +94 -0
- package/dist/steps/utils.mjs.map +1 -0
- package/dist/storage.cjs +68 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +33 -0
- package/dist/storage.d.cts.map +1 -0
- package/dist/storage.d.mts +33 -0
- package/dist/storage.d.mts.map +1 -0
- package/dist/storage.mjs +67 -0
- package/dist/storage.mjs.map +1 -0
- package/dist/subscribable.cjs +25 -0
- package/dist/subscribable.cjs.map +1 -0
- package/dist/subscribable.d.cts +14 -0
- package/dist/subscribable.d.cts.map +1 -0
- package/dist/subscribable.d.mts +14 -0
- package/dist/subscribable.d.mts.map +1 -0
- package/dist/subscribable.mjs +24 -0
- package/dist/subscribable.mjs.map +1 -0
- package/dist/utils/casing.cjs +63 -0
- package/dist/utils/casing.cjs.map +1 -0
- package/dist/utils/casing.d.cts +40 -0
- package/dist/utils/casing.d.cts.map +1 -0
- package/dist/utils/casing.d.mts +40 -0
- package/dist/utils/casing.d.mts.map +1 -0
- package/dist/utils/casing.mjs +57 -0
- package/dist/utils/casing.mjs.map +1 -0
- package/dist/utils/field-types.cjs +23 -0
- package/dist/utils/field-types.cjs.map +1 -0
- package/dist/utils/field-types.d.cts +11 -0
- package/dist/utils/field-types.d.cts.map +1 -0
- package/dist/utils/field-types.d.mts +11 -0
- package/dist/utils/field-types.d.mts.map +1 -0
- package/dist/utils/field-types.mjs +20 -0
- package/dist/utils/field-types.mjs.map +1 -0
- package/dist/utils/helpers.cjs +30 -0
- package/dist/utils/helpers.cjs.map +1 -0
- package/dist/utils/helpers.mjs +27 -0
- package/dist/utils/helpers.mjs.map +1 -0
- package/dist/utils/invariant.cjs +18 -0
- package/dist/utils/invariant.cjs.map +1 -0
- package/dist/utils/invariant.d.cts +5 -0
- package/dist/utils/invariant.d.cts.map +1 -0
- package/dist/utils/invariant.d.mts +5 -0
- package/dist/utils/invariant.d.mts.map +1 -0
- package/dist/utils/invariant.mjs +17 -0
- package/dist/utils/invariant.mjs.map +1 -0
- package/dist/utils/logger.cjs +58 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.cts +53 -0
- package/dist/utils/logger.d.cts.map +1 -0
- package/dist/utils/logger.d.mts +53 -0
- package/dist/utils/logger.d.mts.map +1 -0
- package/dist/utils/logger.mjs +56 -0
- package/dist/utils/logger.mjs.map +1 -0
- package/dist/utils/path.cjs +407 -0
- package/dist/utils/path.cjs.map +1 -0
- package/dist/utils/path.d.cts +139 -0
- package/dist/utils/path.d.cts.map +1 -0
- package/dist/utils/path.d.mts +139 -0
- package/dist/utils/path.d.mts.map +1 -0
- package/dist/utils/path.mjs +401 -0
- package/dist/utils/path.mjs.map +1 -0
- package/dist/utils/types.d.cts +25 -0
- package/dist/utils/types.d.cts.map +1 -0
- package/dist/utils/types.d.mts +25 -0
- package/dist/utils/types.d.mts.map +1 -0
- package/dist/utils/validator.cjs +12 -0
- package/dist/utils/validator.cjs.map +1 -0
- package/dist/utils/validator.d.cts +77 -0
- package/dist/utils/validator.d.cts.map +1 -0
- package/dist/utils/validator.d.mts +77 -0
- package/dist/utils/validator.d.mts.map +1 -0
- package/dist/utils/validator.mjs +11 -0
- package/dist/utils/validator.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/utils/logger.d.ts
|
|
2
|
+
type LogLevel = 'info' | 'warn' | 'error';
|
|
3
|
+
type MultiStepFormLoggerOptions = {
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
prefix?: string | ((prefix: typeof DEFAULT_LOGGER_PREFIX) => string);
|
|
6
|
+
includeTimestamp?: boolean;
|
|
7
|
+
throwOnError?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type WrapWithOptions = '[]' | '{}' | 'none';
|
|
10
|
+
type ReplacePrefixOptions = {
|
|
11
|
+
action: 'replace';
|
|
12
|
+
value: string;
|
|
13
|
+
wrapWith?: WrapWithOptions;
|
|
14
|
+
};
|
|
15
|
+
type AppendOrPrependPrefixOptions = {
|
|
16
|
+
action: 'append' | 'prepend';
|
|
17
|
+
value: string;
|
|
18
|
+
delimiter?: string;
|
|
19
|
+
wrapWith?: {
|
|
20
|
+
originalPrefix?: WrapWithOptions;
|
|
21
|
+
addedPrefix?: WrapWithOptions;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type PrefixOptions = ReplacePrefixOptions | AppendOrPrependPrefixOptions;
|
|
25
|
+
type BaseLogOptions = {
|
|
26
|
+
prefix?: PrefixOptions;
|
|
27
|
+
logLevelOptions?: {
|
|
28
|
+
level?: LogLevel;
|
|
29
|
+
wrapWith?: WrapWithOptions;
|
|
30
|
+
};
|
|
31
|
+
includeTimestamp?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type ErrorLogOptions = BaseLogOptions & {
|
|
34
|
+
throw?: boolean;
|
|
35
|
+
};
|
|
36
|
+
declare const DEFAULT_LOGGER_PREFIX = "MultiStepFormSchema";
|
|
37
|
+
declare class MultiStepFormLogger {
|
|
38
|
+
private readonly debug;
|
|
39
|
+
private readonly prefix;
|
|
40
|
+
private readonly includeTimestamp;
|
|
41
|
+
private readonly throwOnError;
|
|
42
|
+
constructor(options?: MultiStepFormLoggerOptions);
|
|
43
|
+
private wrapValue;
|
|
44
|
+
private formatPrefix;
|
|
45
|
+
private formatMessage;
|
|
46
|
+
info(message: string, options?: BaseLogOptions): void;
|
|
47
|
+
warn(message: string, options?: BaseLogOptions): void;
|
|
48
|
+
error(message: string, options?: BaseLogOptions): void;
|
|
49
|
+
error(message: string, options?: ErrorLogOptions): never;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger };
|
|
53
|
+
//# sourceMappingURL=logger.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.cts","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":[],"mappings":";KAAK,QAAA;KACA,0BAAA,GADQ;EACR,KAAA,CAAA,EAAA,OAAA;EAOA,MAAA,CAAA,EAAA,MAAA,GAAe,CAAA,CAAA,MAAA,EAAA,OALiB,qBAKjB,EAAA,GAAA,MAAA,CAAA;EACf,gBAAA,CAAA,EAAA,OAAoB;EAKpB,YAAA,CAAA,EAAA,OAAA;AAM4B,CAAA;AAGuC,KAfnE,eAAA,GAgBc,IAAA,GAAA,IAAA,GAAA,MAAA;KAfd,oBAAA,GAgBM;EAEC,MAAA,EAAA,SAAA;EACG,KAAA,EAAA,MAAA;EAAe,QAAA,CAAA,EAhBjB,eAgBiB;AAAA,CAAA;AAQ9B,KAtBK,4BAAA,GAsB6B;EACrB,MAAA,EAAA,QAAA,GAAA,SAAmB;EAMR,KAAA,EAAA,MAAA;EAgGU,SAAA,CAAA,EAAA,MAAA;EAQA,QAAA,CAAA,EAAA;IAQC,cAAA,CAAA,EAxId,eAwIc;IACA,WAAA,CAAA,EAxIjB,eAwIiB;EAAe,CAAA;;KArI7C,aAAA,GAAgB,uBAAuB;KACvC,cAAA;WACM;;YAEC;eACG;;;;KAIV,eAAA,GAAkB;;;cAIV,qBAAA;cACA,mBAAA;;;;;wBAMW;;;;kCAgGU;kCAQA;mCAQC;mCACA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/utils/logger.d.ts
|
|
2
|
+
type LogLevel = 'info' | 'warn' | 'error';
|
|
3
|
+
type MultiStepFormLoggerOptions = {
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
prefix?: string | ((prefix: typeof DEFAULT_LOGGER_PREFIX) => string);
|
|
6
|
+
includeTimestamp?: boolean;
|
|
7
|
+
throwOnError?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type WrapWithOptions = '[]' | '{}' | 'none';
|
|
10
|
+
type ReplacePrefixOptions = {
|
|
11
|
+
action: 'replace';
|
|
12
|
+
value: string;
|
|
13
|
+
wrapWith?: WrapWithOptions;
|
|
14
|
+
};
|
|
15
|
+
type AppendOrPrependPrefixOptions = {
|
|
16
|
+
action: 'append' | 'prepend';
|
|
17
|
+
value: string;
|
|
18
|
+
delimiter?: string;
|
|
19
|
+
wrapWith?: {
|
|
20
|
+
originalPrefix?: WrapWithOptions;
|
|
21
|
+
addedPrefix?: WrapWithOptions;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type PrefixOptions = ReplacePrefixOptions | AppendOrPrependPrefixOptions;
|
|
25
|
+
type BaseLogOptions = {
|
|
26
|
+
prefix?: PrefixOptions;
|
|
27
|
+
logLevelOptions?: {
|
|
28
|
+
level?: LogLevel;
|
|
29
|
+
wrapWith?: WrapWithOptions;
|
|
30
|
+
};
|
|
31
|
+
includeTimestamp?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type ErrorLogOptions = BaseLogOptions & {
|
|
34
|
+
throw?: boolean;
|
|
35
|
+
};
|
|
36
|
+
declare const DEFAULT_LOGGER_PREFIX = "MultiStepFormSchema";
|
|
37
|
+
declare class MultiStepFormLogger {
|
|
38
|
+
private readonly debug;
|
|
39
|
+
private readonly prefix;
|
|
40
|
+
private readonly includeTimestamp;
|
|
41
|
+
private readonly throwOnError;
|
|
42
|
+
constructor(options?: MultiStepFormLoggerOptions);
|
|
43
|
+
private wrapValue;
|
|
44
|
+
private formatPrefix;
|
|
45
|
+
private formatMessage;
|
|
46
|
+
info(message: string, options?: BaseLogOptions): void;
|
|
47
|
+
warn(message: string, options?: BaseLogOptions): void;
|
|
48
|
+
error(message: string, options?: BaseLogOptions): void;
|
|
49
|
+
error(message: string, options?: ErrorLogOptions): never;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger };
|
|
53
|
+
//# sourceMappingURL=logger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.mts","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":[],"mappings":";KAAK,QAAA;KACA,0BAAA,GADQ;EACR,KAAA,CAAA,EAAA,OAAA;EAOA,MAAA,CAAA,EAAA,MAAA,GAAe,CAAA,CAAA,MAAA,EAAA,OALiB,qBAKjB,EAAA,GAAA,MAAA,CAAA;EACf,gBAAA,CAAA,EAAA,OAAoB;EAKpB,YAAA,CAAA,EAAA,OAAA;AAM4B,CAAA;AAGuC,KAfnE,eAAA,GAgBc,IAAA,GAAA,IAAA,GAAA,MAAA;KAfd,oBAAA,GAgBM;EAEC,MAAA,EAAA,SAAA;EACG,KAAA,EAAA,MAAA;EAAe,QAAA,CAAA,EAhBjB,eAgBiB;AAAA,CAAA;AAQ9B,KAtBK,4BAAA,GAsB6B;EACrB,MAAA,EAAA,QAAA,GAAA,SAAmB;EAMR,KAAA,EAAA,MAAA;EAgGU,SAAA,CAAA,EAAA,MAAA;EAQA,QAAA,CAAA,EAAA;IAQC,cAAA,CAAA,EAxId,eAwIc;IACA,WAAA,CAAA,EAxIjB,eAwIiB;EAAe,CAAA;;KArI7C,aAAA,GAAgB,uBAAuB;KACvC,cAAA;WACM;;YAEC;eACG;;;;KAIV,eAAA,GAAkB;;;cAIV,qBAAA;cACA,mBAAA;;;;;wBAMW;;;;kCAgGU;kCAQA;mCAQC;mCACA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/utils/logger.ts
|
|
2
|
+
const DEFAULT_LOGGER_PREFIX = "MultiStepFormSchema";
|
|
3
|
+
var MultiStepFormLogger = class {
|
|
4
|
+
debug;
|
|
5
|
+
prefix = DEFAULT_LOGGER_PREFIX;
|
|
6
|
+
includeTimestamp = false;
|
|
7
|
+
throwOnError = false;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.debug = options?.debug ?? false;
|
|
10
|
+
if (this.debug && options?.debug) {
|
|
11
|
+
const { includeTimestamp = false, prefix = DEFAULT_LOGGER_PREFIX, throwOnError = false } = options;
|
|
12
|
+
this.includeTimestamp = includeTimestamp;
|
|
13
|
+
this.prefix = typeof prefix === "string" ? prefix : prefix(DEFAULT_LOGGER_PREFIX);
|
|
14
|
+
this.throwOnError = throwOnError;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
wrapValue(wrapWith, value) {
|
|
18
|
+
if (wrapWith === "[]") return `[${value}]`;
|
|
19
|
+
if (wrapWith === "{}") return `{${value}}`;
|
|
20
|
+
if (wrapWith === "none") return value;
|
|
21
|
+
throw new Error(`The first argument ${wrapWith} is not valid. Valid options include: "[]", "{}", and "none"`);
|
|
22
|
+
}
|
|
23
|
+
formatPrefix(options) {
|
|
24
|
+
if (!options) return this.prefix;
|
|
25
|
+
const { action, value, wrapWith } = options;
|
|
26
|
+
if (action === "replace") return this.wrapValue(wrapWith ?? "[]", value);
|
|
27
|
+
const { delimiter } = options;
|
|
28
|
+
if (action === "append") return `${this.wrapValue(wrapWith?.originalPrefix ?? "[]", this.prefix)}${delimiter}${this.wrapValue(wrapWith?.addedPrefix ?? "[]", value)}`.trim();
|
|
29
|
+
if (action === "prepend") return `${this.wrapValue(wrapWith?.addedPrefix ?? "[]", value)}${delimiter}${this.wrapValue(wrapWith?.originalPrefix ?? "[]", this.prefix)}`.trim();
|
|
30
|
+
return this.prefix;
|
|
31
|
+
}
|
|
32
|
+
formatMessage(level, message, options) {
|
|
33
|
+
const { includeTimestamp = this.includeTimestamp, prefix, logLevelOptions } = options ?? {};
|
|
34
|
+
const formattedMessage = `${this.formatPrefix(prefix)} ${this.wrapValue(logLevelOptions?.wrapWith ?? "[]", (logLevelOptions?.level ?? level).toUpperCase())} ${message}`;
|
|
35
|
+
if (includeTimestamp) return `[${(/* @__PURE__ */ new Date()).toISOString()}] ${formattedMessage}`;
|
|
36
|
+
return formattedMessage;
|
|
37
|
+
}
|
|
38
|
+
info(message, options) {
|
|
39
|
+
if (!this.debug) return;
|
|
40
|
+
console.info(this.formatMessage("info", message, options));
|
|
41
|
+
}
|
|
42
|
+
warn(message, options) {
|
|
43
|
+
if (!this.debug) return;
|
|
44
|
+
console.warn(this.formatMessage("warn", message, options));
|
|
45
|
+
}
|
|
46
|
+
error(message, options) {
|
|
47
|
+
if (!this.debug) return;
|
|
48
|
+
const formatted = this.formatMessage("error", message, options);
|
|
49
|
+
console.error(formatted);
|
|
50
|
+
if (options?.throw ?? this.throwOnError) throw new Error(formatted);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DEFAULT_LOGGER_PREFIX, MultiStepFormLogger };
|
|
56
|
+
//# sourceMappingURL=logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["type LogLevel = 'info' | 'warn' | 'error';\ntype MultiStepFormLoggerOptions = {\n debug?: boolean;\n prefix?: string | ((prefix: typeof DEFAULT_LOGGER_PREFIX) => string);\n includeTimestamp?: boolean;\n throwOnError?: boolean;\n};\n\ntype WrapWithOptions = '[]' | '{}' | 'none';\ntype ReplacePrefixOptions = {\n action: 'replace';\n value: string;\n wrapWith?: WrapWithOptions;\n};\ntype AppendOrPrependPrefixOptions = {\n action: 'append' | 'prepend';\n value: string;\n delimiter?: string;\n wrapWith?: {\n originalPrefix?: WrapWithOptions;\n addedPrefix?: WrapWithOptions;\n };\n};\ntype PrefixOptions = ReplacePrefixOptions | AppendOrPrependPrefixOptions;\ntype BaseLogOptions = {\n prefix?: PrefixOptions;\n logLevelOptions?: {\n level?: LogLevel;\n wrapWith?: WrapWithOptions;\n };\n includeTimestamp?: boolean;\n};\ntype ErrorLogOptions = BaseLogOptions & {\n throw?: boolean;\n};\n\nexport const DEFAULT_LOGGER_PREFIX = 'MultiStepFormSchema';\nexport class MultiStepFormLogger {\n private readonly debug: boolean;\n private readonly prefix: string = DEFAULT_LOGGER_PREFIX;\n private readonly includeTimestamp: boolean = false;\n private readonly throwOnError: boolean = false;\n\n constructor(options?: MultiStepFormLoggerOptions) {\n this.debug = options?.debug ?? false;\n if (this.debug && options?.debug) {\n const {\n includeTimestamp = false,\n prefix = DEFAULT_LOGGER_PREFIX,\n throwOnError = false,\n } = options;\n\n this.includeTimestamp = includeTimestamp;\n this.prefix =\n typeof prefix === 'string' ? prefix : prefix(DEFAULT_LOGGER_PREFIX);\n this.throwOnError = throwOnError;\n }\n }\n\n private wrapValue(wrapWith: WrapWithOptions, value: string) {\n if (wrapWith === '[]') {\n return `[${value}]`;\n }\n\n if (wrapWith === '{}') {\n return `{${value}}`;\n }\n\n if (wrapWith === 'none') {\n return value;\n }\n\n throw new Error(\n `The first argument ${wrapWith} is not valid. Valid options include: \"[]\", \"{}\", and \"none\"`\n );\n }\n\n private formatPrefix(options: PrefixOptions | undefined) {\n if (!options) {\n return this.prefix;\n }\n\n const { action, value, wrapWith } = options;\n\n if (action === 'replace') {\n return this.wrapValue(wrapWith ?? '[]', value);\n }\n\n const { delimiter } = options;\n\n if (action === 'append') {\n return `${this.wrapValue(\n wrapWith?.originalPrefix ?? '[]',\n this.prefix\n )}${delimiter}${this.wrapValue(\n wrapWith?.addedPrefix ?? '[]',\n value\n )}`.trim();\n }\n\n if (action === 'prepend') {\n return `${this.wrapValue(\n wrapWith?.addedPrefix ?? '[]',\n value\n )}${delimiter}${this.wrapValue(\n wrapWith?.originalPrefix ?? '[]',\n this.prefix\n )}`.trim();\n }\n\n return this.prefix;\n }\n\n private formatMessage(\n level: LogLevel,\n message: string,\n options?: BaseLogOptions\n ) {\n const {\n includeTimestamp = this.includeTimestamp,\n prefix,\n logLevelOptions,\n } = options ?? {};\n const formattedPrefix = this.formatPrefix(prefix);\n const formattedLogLevel = this.wrapValue(\n logLevelOptions?.wrapWith ?? '[]',\n (logLevelOptions?.level ?? level).toUpperCase()\n );\n const formattedMessage = `${formattedPrefix} ${formattedLogLevel} ${message}`;\n\n if (includeTimestamp) {\n const timestamp = new Date().toISOString();\n\n return `[${timestamp}] ${formattedMessage}`;\n }\n\n return formattedMessage;\n }\n\n info(message: string, options?: BaseLogOptions) {\n if (!this.debug) {\n return;\n }\n\n console.info(this.formatMessage('info', message, options));\n }\n\n warn(message: string, options?: BaseLogOptions) {\n if (!this.debug) {\n return;\n }\n\n console.warn(this.formatMessage('warn', message, options));\n }\n\n error(message: string, options?: BaseLogOptions): void;\n error(message: string, options?: ErrorLogOptions): never;\n error(message: string, options?: ErrorLogOptions) {\n if (!this.debug) {\n return;\n }\n\n const formatted = this.formatMessage('error', message, options);\n\n console.error(formatted);\n\n const throwOnError = options?.throw ?? this.throwOnError;\n\n if (throwOnError) {\n throw new Error(formatted);\n }\n }\n}\n"],"mappings":";AAoCA,MAAa,wBAAwB;AACrC,IAAa,sBAAb,MAAiC;CAC/B,AAAiB;CACjB,AAAiB,SAAiB;CAClC,AAAiB,mBAA4B;CAC7C,AAAiB,eAAwB;CAEzC,YAAY,SAAsC;AAChD,OAAK,QAAQ,SAAS,SAAS;AAC/B,MAAI,KAAK,SAAS,SAAS,OAAO;GAChC,MAAM,EACJ,mBAAmB,OACnB,SAAS,uBACT,eAAe,UACb;AAEJ,QAAK,mBAAmB;AACxB,QAAK,SACH,OAAO,WAAW,WAAW,SAAS,OAAO,sBAAsB;AACrE,QAAK,eAAe;;;CAIxB,AAAQ,UAAU,UAA2B,OAAe;AAC1D,MAAI,aAAa,KACf,QAAO,IAAI,MAAM;AAGnB,MAAI,aAAa,KACf,QAAO,IAAI,MAAM;AAGnB,MAAI,aAAa,OACf,QAAO;AAGT,QAAM,IAAI,MACR,sBAAsB,SAAS,8DAChC;;CAGH,AAAQ,aAAa,SAAoC;AACvD,MAAI,CAAC,QACH,QAAO,KAAK;EAGd,MAAM,EAAE,QAAQ,OAAO,aAAa;AAEpC,MAAI,WAAW,UACb,QAAO,KAAK,UAAU,YAAY,MAAM,MAAM;EAGhD,MAAM,EAAE,cAAc;AAEtB,MAAI,WAAW,SACb,QAAO,GAAG,KAAK,UACb,UAAU,kBAAkB,MAC5B,KAAK,OACN,GAAG,YAAY,KAAK,UACnB,UAAU,eAAe,MACzB,MACD,GAAG,MAAM;AAGZ,MAAI,WAAW,UACb,QAAO,GAAG,KAAK,UACb,UAAU,eAAe,MACzB,MACD,GAAG,YAAY,KAAK,UACnB,UAAU,kBAAkB,MAC5B,KAAK,OACN,GAAG,MAAM;AAGZ,SAAO,KAAK;;CAGd,AAAQ,cACN,OACA,SACA,SACA;EACA,MAAM,EACJ,mBAAmB,KAAK,kBACxB,QACA,oBACE,WAAW,EAAE;EAMjB,MAAM,mBAAmB,GALD,KAAK,aAAa,OAAO,CAKL,GAJlB,KAAK,UAC7B,iBAAiB,YAAY,OAC5B,iBAAiB,SAAS,OAAO,aAAa,CAChD,CACgE,GAAG;AAEpE,MAAI,iBAGF,QAAO,qBAFW,IAAI,MAAM,EAAC,aAAa,CAErB,IAAI;AAG3B,SAAO;;CAGT,KAAK,SAAiB,SAA0B;AAC9C,MAAI,CAAC,KAAK,MACR;AAGF,UAAQ,KAAK,KAAK,cAAc,QAAQ,SAAS,QAAQ,CAAC;;CAG5D,KAAK,SAAiB,SAA0B;AAC9C,MAAI,CAAC,KAAK,MACR;AAGF,UAAQ,KAAK,KAAK,cAAc,QAAQ,SAAS,QAAQ,CAAC;;CAK5D,MAAM,SAAiB,SAA2B;AAChD,MAAI,CAAC,KAAK,MACR;EAGF,MAAM,YAAY,KAAK,cAAc,SAAS,SAAS,QAAQ;AAE/D,UAAQ,MAAM,UAAU;AAIxB,MAFqB,SAAS,SAAS,KAAK,aAG1C,OAAM,IAAI,MAAM,UAAU"}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/path.ts
|
|
3
|
+
let path;
|
|
4
|
+
(function(_path) {
|
|
5
|
+
function getBy(obj, path$1) {
|
|
6
|
+
return path$1.split(".").reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
|
|
7
|
+
}
|
|
8
|
+
function setBy(target, path$1, value) {
|
|
9
|
+
const keys = path$1.split(".");
|
|
10
|
+
let current = target;
|
|
11
|
+
for (let i = 0; i < keys.length; i++) {
|
|
12
|
+
const k = keys[i];
|
|
13
|
+
if (i === keys.length - 1) if (current[k] !== void 0 && typeof current[k] === "object" && typeof value === "object" && value !== null) Object.assign(current[k], value);
|
|
14
|
+
else current[k] = value;
|
|
15
|
+
else {
|
|
16
|
+
if (typeof current[k] !== "object" || current[k] === null) current[k] = {};
|
|
17
|
+
current = current[k];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
_path.setBy = setBy;
|
|
23
|
+
function normalizePaths(...paths) {
|
|
24
|
+
const sorted = [...paths].sort((a, b) => b.split(".").length - a.split(".").length);
|
|
25
|
+
const finalPaths = [];
|
|
26
|
+
for (const path$1 of sorted) if (!finalPaths.some((p) => p.startsWith(path$1 + "."))) finalPaths.push(path$1);
|
|
27
|
+
return finalPaths.reverse();
|
|
28
|
+
}
|
|
29
|
+
_path.normalizePaths = normalizePaths;
|
|
30
|
+
function pickBy(obj, ...paths) {
|
|
31
|
+
const norm = normalizePaths(...paths);
|
|
32
|
+
if (norm.length === 1) return getBy(obj, norm[0]);
|
|
33
|
+
const result = {};
|
|
34
|
+
for (const p of norm) setBy(result, p, getBy(obj, p));
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
_path.pickBy = pickBy;
|
|
38
|
+
function createDeep(obj) {
|
|
39
|
+
const paths = [];
|
|
40
|
+
function traverse(current, prefix = "") {
|
|
41
|
+
if (current === null || current === void 0) return;
|
|
42
|
+
if (typeof current !== "object" || Array.isArray(current)) return;
|
|
43
|
+
const keys = Object.keys(current);
|
|
44
|
+
for (const key of keys) {
|
|
45
|
+
const path$1 = prefix ? `${prefix}.${key}` : key;
|
|
46
|
+
paths.push(path$1);
|
|
47
|
+
const value = current[key];
|
|
48
|
+
if (value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value)) traverse(value, path$1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
traverse(obj);
|
|
52
|
+
return paths;
|
|
53
|
+
}
|
|
54
|
+
_path.createDeep = createDeep;
|
|
55
|
+
function defaultExpectedFormat(value) {
|
|
56
|
+
if (value === null) return "null";
|
|
57
|
+
if (Array.isArray(value)) return "Array";
|
|
58
|
+
const t = typeof value;
|
|
59
|
+
if (t !== "object") return t;
|
|
60
|
+
const ctor = value?.constructor?.name;
|
|
61
|
+
return ctor && ctor !== "Object" ? ctor : "object";
|
|
62
|
+
}
|
|
63
|
+
function splitPath(path$1) {
|
|
64
|
+
if (!path$1) return [];
|
|
65
|
+
const parts = [];
|
|
66
|
+
const regex = /[^.[\]]+|\[(\d+)\]/g;
|
|
67
|
+
let m;
|
|
68
|
+
while (m = regex.exec(path$1)) parts.push(m[1] ?? m[0]);
|
|
69
|
+
return parts;
|
|
70
|
+
}
|
|
71
|
+
function getTransformFunction(root, path$1) {
|
|
72
|
+
if (!root) return void 0;
|
|
73
|
+
if (typeof root === "function") return root;
|
|
74
|
+
const segments = splitPath(path$1);
|
|
75
|
+
let node = root;
|
|
76
|
+
let lastFn;
|
|
77
|
+
for (const seg of segments) {
|
|
78
|
+
if (!node) break;
|
|
79
|
+
if (typeof node === "function") {
|
|
80
|
+
lastFn = node;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
node = node[seg];
|
|
84
|
+
if (typeof node === "function") {
|
|
85
|
+
lastFn = node;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return lastFn;
|
|
90
|
+
}
|
|
91
|
+
function formatExpected(rawExpected, path$1, cfg) {
|
|
92
|
+
const fn = getTransformFunction(cfg, path$1);
|
|
93
|
+
if (fn) return fn(rawExpected, path$1);
|
|
94
|
+
return defaultExpectedFormat(rawExpected);
|
|
95
|
+
}
|
|
96
|
+
function isObjectLike(v) {
|
|
97
|
+
return typeof v === "object" && v !== null;
|
|
98
|
+
}
|
|
99
|
+
function deepCompare(expected, actual, basePath, mismatches, options) {
|
|
100
|
+
if (expected === actual) return mismatches;
|
|
101
|
+
if (expected === null || actual === null || typeof expected !== "object" || typeof actual !== "object") {
|
|
102
|
+
const path$2 = basePath || "(root)";
|
|
103
|
+
if (typeof expected !== typeof actual) {
|
|
104
|
+
mismatches.push({
|
|
105
|
+
path: path$2,
|
|
106
|
+
expected: formatExpected(expected, path$2, options.transformExpected),
|
|
107
|
+
actual,
|
|
108
|
+
reason: "type-mismatch"
|
|
109
|
+
});
|
|
110
|
+
return mismatches;
|
|
111
|
+
}
|
|
112
|
+
if (options.includeValueMismatch) mismatches.push({
|
|
113
|
+
path: path$2,
|
|
114
|
+
expected: formatExpected(expected, path$2, options.transformExpected),
|
|
115
|
+
actual,
|
|
116
|
+
reason: "value-mismatch"
|
|
117
|
+
});
|
|
118
|
+
return mismatches;
|
|
119
|
+
}
|
|
120
|
+
if (Array.isArray(expected) || Array.isArray(actual)) {
|
|
121
|
+
if (!Array.isArray(expected) || !Array.isArray(actual)) {
|
|
122
|
+
const path$2 = basePath || "(root)";
|
|
123
|
+
mismatches.push({
|
|
124
|
+
path: path$2,
|
|
125
|
+
expected: formatExpected(expected, path$2, options.transformExpected),
|
|
126
|
+
actual,
|
|
127
|
+
reason: "type-mismatch"
|
|
128
|
+
});
|
|
129
|
+
return mismatches;
|
|
130
|
+
}
|
|
131
|
+
const maxLen = expected.length;
|
|
132
|
+
for (let i = 0; i < maxLen; i++) {
|
|
133
|
+
const expVal = expected[i];
|
|
134
|
+
const actVal = actual[i];
|
|
135
|
+
deepCompare(expVal, actVal, basePath === "" ? `[${i}]` : `${basePath}[${i}]`, mismatches, options);
|
|
136
|
+
}
|
|
137
|
+
return mismatches;
|
|
138
|
+
}
|
|
139
|
+
if (isObjectLike(expected) && isObjectLike(actual)) {
|
|
140
|
+
const expKeys = Object.keys(expected);
|
|
141
|
+
const actKeys = Object.keys(actual);
|
|
142
|
+
for (const key of expKeys) {
|
|
143
|
+
const expVal = expected[key];
|
|
144
|
+
const actVal = actual[key];
|
|
145
|
+
const path$2 = basePath ? `${basePath}.${key}` : key;
|
|
146
|
+
if (!(key in actual)) {
|
|
147
|
+
mismatches.push({
|
|
148
|
+
path: path$2,
|
|
149
|
+
expected: formatExpected(expVal, path$2, options.transformExpected),
|
|
150
|
+
actual: void 0,
|
|
151
|
+
reason: "missing-key"
|
|
152
|
+
});
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
deepCompare(expVal, actVal, path$2, mismatches, options);
|
|
156
|
+
}
|
|
157
|
+
for (const key of actKeys) if (!(key in expected)) {
|
|
158
|
+
const path$2 = basePath ? `${basePath}.${key}` : key;
|
|
159
|
+
mismatches.push({
|
|
160
|
+
path: path$2,
|
|
161
|
+
expected: void 0,
|
|
162
|
+
actual: actual[key],
|
|
163
|
+
reason: "extra-key"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return mismatches;
|
|
167
|
+
}
|
|
168
|
+
const path$1 = basePath || "(root)";
|
|
169
|
+
if (typeof expected !== typeof actual) mismatches.push({
|
|
170
|
+
path: path$1,
|
|
171
|
+
expected: formatExpected(expected, path$1, options.transformExpected),
|
|
172
|
+
actual,
|
|
173
|
+
reason: "type-mismatch"
|
|
174
|
+
});
|
|
175
|
+
else if (options.includeValueMismatch) mismatches.push({
|
|
176
|
+
path: path$1,
|
|
177
|
+
expected: formatExpected(expected, path$1, options.transformExpected),
|
|
178
|
+
actual,
|
|
179
|
+
reason: "value-mismatch"
|
|
180
|
+
});
|
|
181
|
+
return mismatches;
|
|
182
|
+
}
|
|
183
|
+
function equalsAtPaths(obj, paths, actual, options) {
|
|
184
|
+
const expected = pickBy(obj, ...paths);
|
|
185
|
+
const mismatches = [];
|
|
186
|
+
deepCompare(expected, actual, paths.length === 1 ? paths[0] : "", mismatches, { transformExpected: options?.transformExpected });
|
|
187
|
+
return {
|
|
188
|
+
ok: mismatches.length === 0,
|
|
189
|
+
mismatches
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
_path.equalsAtPaths = equalsAtPaths;
|
|
193
|
+
function formatValue(v) {
|
|
194
|
+
if (v === void 0) return "undefined";
|
|
195
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
196
|
+
try {
|
|
197
|
+
return JSON.stringify(v, null, 2);
|
|
198
|
+
} catch {
|
|
199
|
+
return String(v);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function formatReason(m) {
|
|
203
|
+
switch (m.reason) {
|
|
204
|
+
case "missing-key": return "Missing key";
|
|
205
|
+
case "extra-key": return "Extra key";
|
|
206
|
+
case "type-mismatch": return "Type mismatch";
|
|
207
|
+
case "value-mismatch": return "Value mismatch";
|
|
208
|
+
default: return m.reason;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function formatMismatches(result) {
|
|
212
|
+
if (result.ok || result.mismatches.length === 0) return "No mismatches.";
|
|
213
|
+
const lines = [];
|
|
214
|
+
for (const m of result.mismatches) lines.push(`\n● ${formatReason(m)} at "${m.path}":`, ` expected: ${formatValue(m.expected)}`, ` actual: ${formatValue(m.actual)}`, "");
|
|
215
|
+
if (lines.at(-1) === "") lines.pop();
|
|
216
|
+
return lines.join("\n");
|
|
217
|
+
}
|
|
218
|
+
_path.formatMismatches = formatMismatches;
|
|
219
|
+
function printMismatches(result) {
|
|
220
|
+
const msg = formatMismatches(result);
|
|
221
|
+
if (msg !== "No mismatches.") console.error(msg);
|
|
222
|
+
}
|
|
223
|
+
_path.printMismatches = printMismatches;
|
|
224
|
+
function setAtImmutable(root, path$1, value) {
|
|
225
|
+
const keys = path$1.split(".");
|
|
226
|
+
function helper(current, idx) {
|
|
227
|
+
const key = keys[idx];
|
|
228
|
+
const resolvedCurrent = Array.isArray(current) ? [...current] : { ...current };
|
|
229
|
+
if (idx === keys.length - 1) {
|
|
230
|
+
let clone$1 = current && typeof current === "object" ? resolvedCurrent : {};
|
|
231
|
+
clone$1 = {
|
|
232
|
+
...clone$1,
|
|
233
|
+
[key]: value
|
|
234
|
+
};
|
|
235
|
+
return clone$1;
|
|
236
|
+
}
|
|
237
|
+
const updatedChild = helper((current && typeof current === "object" ? current[key] : void 0) ?? {}, idx + 1);
|
|
238
|
+
let clone = current && typeof current === "object" ? resolvedCurrent : {};
|
|
239
|
+
clone = {
|
|
240
|
+
...clone,
|
|
241
|
+
[key]: updatedChild
|
|
242
|
+
};
|
|
243
|
+
return clone;
|
|
244
|
+
}
|
|
245
|
+
return helper(root, 0);
|
|
246
|
+
}
|
|
247
|
+
function findMissingPaths(obj, paths, actual) {
|
|
248
|
+
const keys = [];
|
|
249
|
+
for (const path$1 of paths) {
|
|
250
|
+
const expectedKeys = createDeep(pickBy(obj, path$1));
|
|
251
|
+
const actualKeys = createDeep(actual);
|
|
252
|
+
const missingKeys = expectedKeys.filter((key) => !actualKeys.includes(key)).map((key) => `${path$1}.${key}`);
|
|
253
|
+
keys.push(...missingKeys);
|
|
254
|
+
}
|
|
255
|
+
return keys;
|
|
256
|
+
}
|
|
257
|
+
_path.findMissingPaths = findMissingPaths;
|
|
258
|
+
function getPathThatMatter(path$1) {
|
|
259
|
+
const [, ...rest] = path$1.split(".defaultValue.");
|
|
260
|
+
return rest.join(".");
|
|
261
|
+
}
|
|
262
|
+
function joinAtPath(paths, obj, value) {
|
|
263
|
+
if (paths.length === 1) {
|
|
264
|
+
const [path$1] = paths;
|
|
265
|
+
const missingData = pickBy(obj, ...paths);
|
|
266
|
+
const setPath = getPathThatMatter(path$1);
|
|
267
|
+
if (setPath === "") {
|
|
268
|
+
if (missingData !== null && missingData !== void 0 && typeof missingData === "object") return missingData;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
return setBy(value, setPath, missingData);
|
|
272
|
+
}
|
|
273
|
+
if (paths.length > 1) {
|
|
274
|
+
let resolvedValue = {};
|
|
275
|
+
for (const path$1 of paths) {
|
|
276
|
+
const pathThatMatters = getPathThatMatter(path$1);
|
|
277
|
+
const missing = joinAtPath([path$1], obj, value);
|
|
278
|
+
const valueAtPathThatMatters = getBy(obj, path$1);
|
|
279
|
+
if (Object.keys(resolvedValue).length > 0 && valueAtPathThatMatters !== "undefined") {
|
|
280
|
+
const dataAtPath = pickBy(obj, path$1);
|
|
281
|
+
const [key] = pathThatMatters.split(".");
|
|
282
|
+
if (typeof dataAtPath === "object") {
|
|
283
|
+
if (missing) resolvedValue = {
|
|
284
|
+
...resolvedValue,
|
|
285
|
+
[key]: {
|
|
286
|
+
...resolvedValue[key],
|
|
287
|
+
...missing
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (missing) resolvedValue = {
|
|
294
|
+
...resolvedValue,
|
|
295
|
+
...missing
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return resolvedValue;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
_path.joinAtPath = joinAtPath;
|
|
302
|
+
/**
|
|
303
|
+
* Check if an array contains objects (not primitives)
|
|
304
|
+
*/
|
|
305
|
+
function isArrayOfObjects(arr) {
|
|
306
|
+
return arr.length > 0 && arr.every((item) => item !== null && typeof item === "object" && !Array.isArray(item));
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Merge two array elements, handling objects recursively
|
|
310
|
+
* sourceItem is the new value, targetItem is the original (missing data)
|
|
311
|
+
* We want to preserve targetItem properties and let sourceItem override
|
|
312
|
+
*/
|
|
313
|
+
function mergeArrayElement(sourceItem, targetItem) {
|
|
314
|
+
if (targetItem === void 0) return sourceItem;
|
|
315
|
+
if (sourceItem !== null && typeof sourceItem === "object" && !Array.isArray(sourceItem) && targetItem !== null && typeof targetItem === "object" && !Array.isArray(targetItem)) return mergeObjects(sourceItem, targetItem);
|
|
316
|
+
return sourceItem;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Deep merge two objects recursively
|
|
320
|
+
* Target (original/missing data) is the base, source (new value) overrides
|
|
321
|
+
*/
|
|
322
|
+
function mergeObjects(source, target) {
|
|
323
|
+
const result = { ...target };
|
|
324
|
+
for (const key in source) if (key in result) result[key] = deepMergePreserveType(source[key], result[key]);
|
|
325
|
+
else result[key] = source[key];
|
|
326
|
+
return result;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Deep merge two values while preserving their structure.
|
|
330
|
+
* - Arrays:
|
|
331
|
+
* - If both are arrays of objects: merge element-wise
|
|
332
|
+
* - If both are arrays of primitives: use source (replacement)
|
|
333
|
+
* - Otherwise: use source
|
|
334
|
+
* - Objects: deep merge nested properties
|
|
335
|
+
* - Primitives: use source value
|
|
336
|
+
*/
|
|
337
|
+
function deepMergePreserveType(source, target) {
|
|
338
|
+
if (target === void 0 || target === null) return source;
|
|
339
|
+
if (Array.isArray(source)) {
|
|
340
|
+
if (Array.isArray(target)) {
|
|
341
|
+
const sourceArr = source;
|
|
342
|
+
const targetArr = target;
|
|
343
|
+
if (isArrayOfObjects(sourceArr) && isArrayOfObjects(targetArr)) return sourceArr.map((item, index) => {
|
|
344
|
+
const targetItem = targetArr[index];
|
|
345
|
+
if (targetItem !== void 0) return mergeArrayElement(item, targetItem);
|
|
346
|
+
return item;
|
|
347
|
+
});
|
|
348
|
+
if (sourceArr.length === 0) return source;
|
|
349
|
+
return [...targetArr, ...sourceArr];
|
|
350
|
+
}
|
|
351
|
+
return source;
|
|
352
|
+
}
|
|
353
|
+
if (source !== null && typeof source === "object") {
|
|
354
|
+
if (target !== null && typeof target === "object" && !Array.isArray(target)) return mergeObjects(source, target);
|
|
355
|
+
return source;
|
|
356
|
+
}
|
|
357
|
+
return source;
|
|
358
|
+
}
|
|
359
|
+
function updateAt(options) {
|
|
360
|
+
const { obj, partial, paths, value } = options;
|
|
361
|
+
const norm = normalizePaths(...paths);
|
|
362
|
+
if (norm.length === 0) return obj;
|
|
363
|
+
let result = obj;
|
|
364
|
+
let resolvedValue = value;
|
|
365
|
+
if (partial) {
|
|
366
|
+
let missingData = joinAtPath(findMissingPaths(obj, paths, value), obj, resolvedValue);
|
|
367
|
+
if (missingData === void 0 || typeof missingData === "object" && missingData !== null && Object.keys(missingData).length === 0) {
|
|
368
|
+
if (norm.length === 1) {
|
|
369
|
+
const originalValue = getBy(obj, norm[0]);
|
|
370
|
+
if (originalValue !== void 0) {
|
|
371
|
+
if (Array.isArray(originalValue) && Array.isArray(resolvedValue)) {
|
|
372
|
+
if (resolvedValue.length > 0) missingData = originalValue;
|
|
373
|
+
} else if (originalValue !== null && typeof originalValue === "object" && !Array.isArray(originalValue) && resolvedValue !== null && typeof resolvedValue === "object" && !Array.isArray(resolvedValue)) missingData = originalValue;
|
|
374
|
+
}
|
|
375
|
+
} else if (norm.length > 1) {
|
|
376
|
+
const originalData = {};
|
|
377
|
+
for (const p of norm) {
|
|
378
|
+
const originalValue = getBy(obj, p);
|
|
379
|
+
if (originalValue !== void 0) setBy(originalData, p, originalValue);
|
|
380
|
+
}
|
|
381
|
+
if (Object.keys(originalData).length > 0) missingData = originalData;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
resolvedValue = deepMergePreserveType(resolvedValue, missingData);
|
|
385
|
+
}
|
|
386
|
+
if (norm.length === 1) {
|
|
387
|
+
const path$1 = norm[0];
|
|
388
|
+
result = setAtImmutable(result, path$1, resolvedValue);
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
for (const path$1 of norm) {
|
|
392
|
+
const sub = getBy(resolvedValue, path$1);
|
|
393
|
+
result = setAtImmutable(result, path$1, sub);
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
_path.updateAt = updateAt;
|
|
398
|
+
})(path || (path = {}));
|
|
399
|
+
|
|
400
|
+
//#endregion
|
|
401
|
+
Object.defineProperty(exports, 'path', {
|
|
402
|
+
enumerable: true,
|
|
403
|
+
get: function () {
|
|
404
|
+
return path;
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
//# sourceMappingURL=path.cjs.map
|