lampamazaza-new-contract-types 0.6.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.
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ //#region src/index.ts
2
+ /**
3
+ * Enum of supported intent standards.
4
+ * Generated from the MultiPayload schema variants.
5
+ */
6
+ let IntentStandardEnum = /* @__PURE__ */ function(IntentStandardEnum$1) {
7
+ IntentStandardEnum$1["NEP413"] = "nep413";
8
+ IntentStandardEnum$1["ERC191"] = "erc191";
9
+ IntentStandardEnum$1["TIP191"] = "tip191";
10
+ IntentStandardEnum$1["RAW_ED25519"] = "raw_ed25519";
11
+ IntentStandardEnum$1["WEBAUTHN"] = "webauthn";
12
+ IntentStandardEnum$1["TON_CONNECT"] = "ton_connect";
13
+ IntentStandardEnum$1["SEP53"] = "sep53";
14
+ return IntentStandardEnum$1;
15
+ }({});
16
+
17
+ //#endregion
18
+ export { IntentStandardEnum };
@@ -0,0 +1,50 @@
1
+
2
+ //#region src/standard-schema.ts
3
+ function cloneDeep(value) {
4
+ try {
5
+ return { value: JSON.parse(JSON.stringify(value)) };
6
+ } catch (err) {
7
+ return { issues: [{ message: err instanceof Error ? err.message : "Value is not JSON-serializable" }] };
8
+ }
9
+ }
10
+ function ajvErrorToIssue(error) {
11
+ const path = [];
12
+ if (error.instancePath) for (const segment of error.instancePath.split("/").filter(Boolean)) {
13
+ const asNumber = Number(segment);
14
+ path.push(Number.isNaN(asNumber) ? segment : asNumber);
15
+ }
16
+ return {
17
+ message: error.message ?? "Validation failed",
18
+ path: path.length > 0 ? path : void 0
19
+ };
20
+ }
21
+ function wrapValidator(compileValidator, shouldClone = false) {
22
+ let cached = null;
23
+ function getValidator() {
24
+ if (!cached) cached = compileValidator();
25
+ return cached;
26
+ }
27
+ function validate(value) {
28
+ const validateFunction = getValidator();
29
+ if (shouldClone) {
30
+ const cloneResult = cloneDeep(value);
31
+ if (cloneResult.issues) return cloneResult;
32
+ if (validateFunction(cloneResult.value)) return { value: cloneResult.value };
33
+ } else if (validateFunction(value)) return { value };
34
+ return { issues: (validateFunction.errors ?? []).map((error) => ajvErrorToIssue(error)) };
35
+ }
36
+ return {
37
+ validate,
38
+ get schema() {
39
+ return getValidator().schema;
40
+ },
41
+ "~standard": {
42
+ version: 1,
43
+ vendor: "ajv",
44
+ validate
45
+ }
46
+ };
47
+ }
48
+
49
+ //#endregion
50
+ exports.wrapValidator = wrapValidator;
@@ -0,0 +1,16 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import { AnySchema } from "ajv";
3
+
4
+ //#region src/standard-schema.d.ts
5
+ type ValidationResult<Output> = StandardSchemaV1.Result<Output>;
6
+ type ValidationIssue = StandardSchemaV1.Issue;
7
+ interface Validator<Input, Output> extends StandardSchemaV1<Input, Output> {
8
+ readonly validate: (value: unknown) => ValidationResult<Output>;
9
+ readonly schema: AnySchema;
10
+ }
11
+ /** Extracts the input type from a Validator */
12
+ type InferInput<V> = V extends Validator<infer I, unknown> ? I : never;
13
+ /** Extracts the output type from a Validator */
14
+ type InferOutput<V> = V extends Validator<unknown, infer O> ? O : never;
15
+ //#endregion
16
+ export { InferInput, InferOutput, type StandardSchemaV1, ValidationIssue, ValidationResult, Validator };
@@ -0,0 +1,16 @@
1
+ import { AnySchema } from "ajv";
2
+ import { StandardSchemaV1 } from "@standard-schema/spec";
3
+
4
+ //#region src/standard-schema.d.ts
5
+ type ValidationResult<Output> = StandardSchemaV1.Result<Output>;
6
+ type ValidationIssue = StandardSchemaV1.Issue;
7
+ interface Validator<Input, Output> extends StandardSchemaV1<Input, Output> {
8
+ readonly validate: (value: unknown) => ValidationResult<Output>;
9
+ readonly schema: AnySchema;
10
+ }
11
+ /** Extracts the input type from a Validator */
12
+ type InferInput<V> = V extends Validator<infer I, unknown> ? I : never;
13
+ /** Extracts the output type from a Validator */
14
+ type InferOutput<V> = V extends Validator<unknown, infer O> ? O : never;
15
+ //#endregion
16
+ export { InferInput, InferOutput, type StandardSchemaV1, ValidationIssue, ValidationResult, Validator };
@@ -0,0 +1,49 @@
1
+ //#region src/standard-schema.ts
2
+ function cloneDeep(value) {
3
+ try {
4
+ return { value: JSON.parse(JSON.stringify(value)) };
5
+ } catch (err) {
6
+ return { issues: [{ message: err instanceof Error ? err.message : "Value is not JSON-serializable" }] };
7
+ }
8
+ }
9
+ function ajvErrorToIssue(error) {
10
+ const path = [];
11
+ if (error.instancePath) for (const segment of error.instancePath.split("/").filter(Boolean)) {
12
+ const asNumber = Number(segment);
13
+ path.push(Number.isNaN(asNumber) ? segment : asNumber);
14
+ }
15
+ return {
16
+ message: error.message ?? "Validation failed",
17
+ path: path.length > 0 ? path : void 0
18
+ };
19
+ }
20
+ function wrapValidator(compileValidator, shouldClone = false) {
21
+ let cached = null;
22
+ function getValidator() {
23
+ if (!cached) cached = compileValidator();
24
+ return cached;
25
+ }
26
+ function validate(value) {
27
+ const validateFunction = getValidator();
28
+ if (shouldClone) {
29
+ const cloneResult = cloneDeep(value);
30
+ if (cloneResult.issues) return cloneResult;
31
+ if (validateFunction(cloneResult.value)) return { value: cloneResult.value };
32
+ } else if (validateFunction(value)) return { value };
33
+ return { issues: (validateFunction.errors ?? []).map((error) => ajvErrorToIssue(error)) };
34
+ }
35
+ return {
36
+ validate,
37
+ get schema() {
38
+ return getValidator().schema;
39
+ },
40
+ "~standard": {
41
+ version: 1,
42
+ vendor: "ajv",
43
+ validate
44
+ }
45
+ };
46
+ }
47
+
48
+ //#endregion
49
+ export { wrapValidator };