@taqueria/protocol 0.0.0-pr-823-7c442bb2 → 0.0.0-pr-825-0ffcf17b
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/Alias.ts +27 -29
- package/Base.ts +88 -84
- package/Command.ts +18 -18
- package/Config.ts +132 -129
- package/Crypto.ts +2 -2
- package/EconomicalProtocolHash.ts +19 -19
- package/Environment.ts +28 -28
- package/EphemeralState.ts +186 -179
- package/Faucet.ts +37 -37
- package/HumanReadableIdentifier.ts +17 -17
- package/InstalledPlugin.ts +20 -20
- package/LoadedConfig.ts +36 -36
- package/NetworkConfig.ts +30 -30
- package/Operation.ts +60 -61
- package/Option.ts +46 -46
- package/ParsedOperation.ts +23 -23
- package/ParsedPluginInfo.ts +41 -41
- package/PersistentState.ts +45 -46
- package/PluginInfo.ts +58 -59
- package/PositionalArg.ts +39 -39
- package/Provisioner.ts +51 -51
- package/ProvisionerID.ts +18 -18
- package/Provisions.ts +59 -50
- package/PublicKeyHash.ts +22 -22
- package/RequestArgs.ts +57 -57
- package/SHA256.ts +32 -33
- package/SandboxAccountConfig.ts +25 -25
- package/SandboxConfig.ts +52 -52
- package/SanitizedAbsPath.ts +18 -18
- package/SanitizedArgs.ts +134 -131
- package/SanitizedPath.ts +20 -20
- package/SingleChar.ts +17 -17
- package/TaqError.ts +61 -58
- package/Task.ts +59 -59
- package/Timestamp.ts +18 -18
- package/Tz.ts +15 -15
- package/Url.ts +20 -20
- package/Verb.ts +18 -18
- package/VersionNumber.ts +18 -19
- package/i18n.ts +56 -54
- package/package.json +39 -39
- package/taqueria-protocol-types.ts +86 -75
package/Alias.ts
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import * as SingleChar from '@taqueria/protocol/SingleChar';
|
|
3
|
+
import * as Verb from '@taqueria/protocol/Verb';
|
|
4
|
+
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
export const rawSchema = z
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
7
|
+
.union([
|
|
8
|
+
Verb.rawSchema,
|
|
9
|
+
SingleChar.rawSchema,
|
|
10
|
+
], { description: 'Alias' });
|
|
12
11
|
|
|
13
12
|
export const internalSchema = z
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
13
|
+
.union([
|
|
14
|
+
Verb.schemas.schema,
|
|
15
|
+
SingleChar.schemas.schema,
|
|
16
|
+
], { description: 'Alias' });
|
|
19
17
|
|
|
20
|
-
type RawInput = z.infer<typeof rawSchema
|
|
21
|
-
type Input = z.infer<typeof internalSchema
|
|
18
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
19
|
+
type Input = z.infer<typeof internalSchema>;
|
|
22
20
|
|
|
23
|
-
const {schemas: generatedSchemas, factory} = createType<RawInput, Input>({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
21
|
+
const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
|
|
22
|
+
isStringLike: true,
|
|
23
|
+
rawSchema,
|
|
24
|
+
internalSchema,
|
|
25
|
+
parseErrMsg: (value: unknown) => `${value} is not a valid alias`,
|
|
26
|
+
unknownErrMsg: 'Something went wrong trying to parse an alias',
|
|
27
|
+
});
|
|
30
28
|
|
|
31
|
-
export type Alias = z.infer<typeof generatedSchemas.schema
|
|
29
|
+
export type Alias = z.infer<typeof generatedSchemas.schema>;
|
|
32
30
|
|
|
33
|
-
export type t = Alias
|
|
31
|
+
export type t = Alias;
|
|
34
32
|
|
|
35
|
-
export const {create, of, make} = factory
|
|
33
|
+
export const { create, of, make } = factory;
|
|
36
34
|
|
|
37
35
|
export const schemas = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
36
|
+
...generatedSchemas,
|
|
37
|
+
schema: generatedSchemas.schema.transform(val => val as Alias),
|
|
38
|
+
};
|
package/Base.ts
CHANGED
|
@@ -1,51 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { toFutureParseErr, toFutureParseUnknownErr } from '@taqueria/protocol/TaqError';
|
|
2
|
+
import { FutureInstance, resolve } from 'fluture';
|
|
3
|
+
import { z, ZodError, ZodSchema } from 'zod';
|
|
4
4
|
|
|
5
|
-
type Future<L, R> = FutureInstance<L, R
|
|
5
|
+
type Future<L, R> = FutureInstance<L, R>;
|
|
6
6
|
|
|
7
|
-
type ErrMsg = string | ((value: unknown) => string)
|
|
7
|
+
type ErrMsg = string | ((value: unknown) => string);
|
|
8
8
|
|
|
9
9
|
interface CreateSchemaParams {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
rawSchema: ZodSchema;
|
|
11
|
+
internalSchema?: ZodSchema;
|
|
12
|
+
transformer?: (value: unknown) => unknown;
|
|
13
|
+
isStringLike?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface CreateTypeParams extends CreateSchemaParams {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
parseErrMsg: ErrMsg;
|
|
18
|
+
unknownErrMsg: ErrMsg;
|
|
19
19
|
}
|
|
20
|
-
export type Flatten<T> = { [k in keyof T]: T[k] }
|
|
20
|
+
export type Flatten<T> = { [k in keyof T]: T[k] };
|
|
21
21
|
|
|
22
22
|
export const createSchema = <I>(params: CreateSchemaParams) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
const { rawSchema, isStringLike } = params;
|
|
24
|
+
const internalSchema = params.internalSchema ?? params.rawSchema;
|
|
25
|
+
const noop = (val: unknown) => val;
|
|
26
|
+
const transformer = params.transformer ?? noop;
|
|
27
|
+
|
|
28
|
+
const schema = isStringLike
|
|
29
|
+
? internalSchema
|
|
30
|
+
.transform((val: unknown) =>
|
|
31
|
+
transformer(val) as I & {
|
|
32
|
+
readonly __kind: 'generated' & z.infer<typeof internalSchema>;
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
: internalSchema
|
|
36
|
+
.transform((val: unknown) =>
|
|
37
|
+
transformer(val) as Flatten<
|
|
38
|
+
I & {
|
|
39
|
+
readonly __kind: 'generated' & z.infer<typeof internalSchema>;
|
|
40
|
+
}
|
|
41
|
+
>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
type GeneratedSchema = typeof schema;
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
rawSchema,
|
|
48
|
+
internalSchema,
|
|
49
|
+
schema,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// TODO:
|
|
49
54
|
// TypeScript appears to have a bug with default generic values
|
|
50
55
|
// For instance, I'd like to use this:
|
|
51
56
|
// export const createType = <R, I = R>(params: CreateTypeParams) => {
|
|
@@ -53,49 +58,48 @@ export const createSchema = <I>(params: CreateSchemaParams) => {
|
|
|
53
58
|
// However, I == unknown when having I default to R if no I was given.
|
|
54
59
|
// So, we need to require R and I explicitly
|
|
55
60
|
export const createType = <R, I>(params: CreateTypeParams) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
export default createType
|
|
61
|
+
const schemas = createSchema<I>(params);
|
|
62
|
+
const { parseErrMsg, unknownErrMsg } = params;
|
|
63
|
+
|
|
64
|
+
type T = z.infer<typeof schemas.schema>;
|
|
65
|
+
|
|
66
|
+
const internalOf = (input: unknown) => {
|
|
67
|
+
try {
|
|
68
|
+
return resolve<T>(schemas.schema.parse(input));
|
|
69
|
+
} catch (previous) {
|
|
70
|
+
const parseMsg = typeof parseErrMsg === 'string'
|
|
71
|
+
? parseErrMsg
|
|
72
|
+
: parseErrMsg(input);
|
|
73
|
+
|
|
74
|
+
const unknownMsg = typeof unknownErrMsg === 'string'
|
|
75
|
+
? unknownErrMsg
|
|
76
|
+
: unknownErrMsg(input);
|
|
77
|
+
|
|
78
|
+
if (previous instanceof ZodError) {
|
|
79
|
+
return toFutureParseErr<T>(previous, parseMsg, input);
|
|
80
|
+
}
|
|
81
|
+
return toFutureParseUnknownErr<T>(previous, unknownMsg, input);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const of = internalOf;
|
|
85
|
+
|
|
86
|
+
const make = (input: I) => internalOf(input);
|
|
87
|
+
|
|
88
|
+
const create = (input: R | I) => schemas.schema.parse(input) as T;
|
|
89
|
+
|
|
90
|
+
const from = (input: unknown) => schemas.schema.parse(input) as T;
|
|
91
|
+
|
|
92
|
+
const factory = {
|
|
93
|
+
make,
|
|
94
|
+
of,
|
|
95
|
+
create,
|
|
96
|
+
from,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
schemas,
|
|
101
|
+
factory,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default createType;
|
package/Command.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
export const rawSchema = z
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
.string({ description: 'Command' })
|
|
6
|
+
.min(1)
|
|
7
|
+
.regex(/^([A-Za-z-_ ]+ ?)((\[.+\] ?)|(\<.+\>) ?)*$/, 'Must be a command that can be interpreted using yargs');
|
|
8
8
|
|
|
9
|
-
type RawInput = z.infer<typeof rawSchema
|
|
9
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
10
10
|
|
|
11
|
-
const {schemas: generatedSchemas, factory} = createType<RawInput, RawInput>({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
11
|
+
const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
12
|
+
isStringLike: true,
|
|
13
|
+
rawSchema,
|
|
14
|
+
parseErrMsg: (value: unknown) => `${value} is an invalid command. Expected format is: taskName [optional] <required>`,
|
|
15
|
+
unknownErrMsg: 'Something went wrong when parsing the command',
|
|
16
|
+
});
|
|
17
17
|
|
|
18
|
-
export type Command = z.infer<typeof generatedSchemas.schema
|
|
19
|
-
export type t = Command
|
|
20
|
-
export const {create, make, of} = factory
|
|
18
|
+
export type Command = z.infer<typeof generatedSchemas.schema>;
|
|
19
|
+
export type t = Command;
|
|
20
|
+
export const { create, make, of } = factory;
|
|
21
21
|
export const schemas = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
...generatedSchemas,
|
|
23
|
+
schema: generatedSchemas.schema.transform(val => val as Command),
|
|
24
|
+
};
|
package/Config.ts
CHANGED
|
@@ -1,152 +1,155 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as Tz from
|
|
7
|
-
import
|
|
1
|
+
import createType, { Flatten } from '@taqueria/protocol/Base';
|
|
2
|
+
import * as Environment from '@taqueria/protocol/Environment';
|
|
3
|
+
import * as InstalledPlugin from '@taqueria/protocol/InstalledPlugin';
|
|
4
|
+
import * as NetworkConfig from '@taqueria/protocol/NetworkConfig';
|
|
5
|
+
import * as SandboxConfig from '@taqueria/protocol/SandboxConfig';
|
|
6
|
+
import * as Tz from '@taqueria/protocol/Tz';
|
|
7
|
+
import { z } from 'zod';
|
|
8
8
|
|
|
9
9
|
export const pluginsRawSchema = z.preprocess(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
10
|
+
val => val ?? [],
|
|
11
|
+
z.array(
|
|
12
|
+
InstalledPlugin.rawSchema,
|
|
13
|
+
{ description: 'config.plugins' },
|
|
14
|
+
),
|
|
15
|
+
);
|
|
15
16
|
|
|
16
17
|
export const pluginsInternalSchema = z.preprocess(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
18
|
+
val => val ?? [],
|
|
19
|
+
z.array(
|
|
20
|
+
InstalledPlugin.schemas.schema,
|
|
21
|
+
{ description: 'config.plugins' },
|
|
22
|
+
),
|
|
23
|
+
);
|
|
22
24
|
|
|
23
25
|
const networkMap = z
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
.record(
|
|
27
|
+
z.union([
|
|
28
|
+
NetworkConfig.schemas.schema,
|
|
29
|
+
z.string({ description: 'config.network' })
|
|
30
|
+
.nonempty('Default network must reference the name of an existing network configuration.'),
|
|
31
|
+
]),
|
|
32
|
+
{ description: 'Network configurations' },
|
|
33
|
+
)
|
|
34
|
+
.optional();
|
|
33
35
|
|
|
34
36
|
const sandboxMap = z
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
.record(
|
|
38
|
+
z.union([
|
|
39
|
+
SandboxConfig.schemas.schema,
|
|
40
|
+
z.string({ description: 'config.sandbox' })
|
|
41
|
+
.min(1, 'Default sandbox must reference the name of an existing sandbox configuration.'),
|
|
42
|
+
]),
|
|
43
|
+
{ description: 'Sandbox configurations' },
|
|
44
|
+
)
|
|
45
|
+
.optional();
|
|
44
46
|
|
|
45
47
|
const environmentMap = z
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
.record(
|
|
49
|
+
z.union([
|
|
50
|
+
Environment.schemas.schema,
|
|
51
|
+
z.string().min(1, 'Default environment must reference the name of an existing environment.'),
|
|
52
|
+
]),
|
|
53
|
+
{ description: 'Environment configurations' },
|
|
54
|
+
)
|
|
55
|
+
.optional();
|
|
54
56
|
|
|
55
57
|
const accountsMap = z.preprocess(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
58
|
+
(val: unknown) =>
|
|
59
|
+
val ?? {
|
|
60
|
+
'bob': '5_000_000_000',
|
|
61
|
+
'alice': '5_000_000_000',
|
|
62
|
+
'john': '5_000_000_000',
|
|
63
|
+
},
|
|
64
|
+
z.record(
|
|
65
|
+
z.union([Tz.rawSchema, z.number()]),
|
|
66
|
+
{ description: 'config.accounts' },
|
|
67
|
+
),
|
|
68
|
+
);
|
|
66
69
|
|
|
67
70
|
const commonSchema = z.object({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}).describe(
|
|
71
|
+
language: z.preprocess(
|
|
72
|
+
val => val ?? 'en',
|
|
73
|
+
z.union([
|
|
74
|
+
z.literal('en'),
|
|
75
|
+
z.literal('fr'),
|
|
76
|
+
], { description: 'config.language' })
|
|
77
|
+
.optional(),
|
|
78
|
+
),
|
|
79
|
+
plugins: pluginsInternalSchema.optional(),
|
|
80
|
+
contractsDir: z
|
|
81
|
+
.preprocess(
|
|
82
|
+
(val: unknown) => val ?? 'contracts',
|
|
83
|
+
z.string({ description: 'config.contractsDir' })
|
|
84
|
+
.min(1, 'config.contractsDir must have a value'),
|
|
85
|
+
),
|
|
86
|
+
artifactsDir: z
|
|
87
|
+
.preprocess(
|
|
88
|
+
(val: unknown) => val ?? 'artifacts',
|
|
89
|
+
z.string({ description: 'config.artifactsDir' })
|
|
90
|
+
.min(1, 'config.artifactsDir must have a value'),
|
|
91
|
+
),
|
|
92
|
+
}).describe('config');
|
|
90
93
|
|
|
91
94
|
export const internalSchema = commonSchema.extend({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
95
|
+
network: networkMap,
|
|
96
|
+
sandbox: sandboxMap,
|
|
97
|
+
environment: environmentMap,
|
|
98
|
+
accounts: accountsMap,
|
|
99
|
+
});
|
|
97
100
|
|
|
98
101
|
export const rawSchema = commonSchema.extend({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}).describe(
|
|
102
|
+
plugins: pluginsRawSchema.optional(),
|
|
103
|
+
network: z
|
|
104
|
+
.record(
|
|
105
|
+
z.union([
|
|
106
|
+
NetworkConfig.rawSchema,
|
|
107
|
+
z.string({ description: 'config.network' })
|
|
108
|
+
.min(1, 'Default network must reference the name of an existing network configuration.'),
|
|
109
|
+
]),
|
|
110
|
+
)
|
|
111
|
+
.optional(),
|
|
112
|
+
sandbox: z
|
|
113
|
+
.record(
|
|
114
|
+
z.union([
|
|
115
|
+
SandboxConfig.rawSchema,
|
|
116
|
+
z.string({ description: 'config.sandbox' })
|
|
117
|
+
.min(1, 'Default sandbox must reference the name of an existing sandbox configuration.'),
|
|
118
|
+
]),
|
|
119
|
+
)
|
|
120
|
+
.optional(),
|
|
121
|
+
environment: z
|
|
122
|
+
.record(
|
|
123
|
+
z.union([
|
|
124
|
+
Environment.rawSchema,
|
|
125
|
+
z.string({ description: 'config.environment' })
|
|
126
|
+
.min(1, 'Default environment must reference the name of an existing environment.'),
|
|
127
|
+
]),
|
|
128
|
+
)
|
|
129
|
+
.optional(),
|
|
130
|
+
accounts: z
|
|
131
|
+
.record(
|
|
132
|
+
z.union([Tz.rawSchema, z.number()]),
|
|
133
|
+
{ description: 'config.accounts' },
|
|
134
|
+
)
|
|
135
|
+
.optional(),
|
|
136
|
+
}).describe('config');
|
|
134
137
|
|
|
135
|
-
type RawInput = z.infer<typeof rawSchema
|
|
136
|
-
type Input = z.infer<typeof internalSchema
|
|
138
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
139
|
+
type Input = z.infer<typeof internalSchema>;
|
|
137
140
|
|
|
138
|
-
export const {schemas: generatedSchemas, factory} = createType<RawInput, Input>({
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
})
|
|
141
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
|
|
142
|
+
rawSchema,
|
|
143
|
+
internalSchema,
|
|
144
|
+
parseErrMsg: (value: unknown) => `${value} is not a configuration`,
|
|
145
|
+
unknownErrMsg: 'Something went wrong trying to parse your configuration',
|
|
146
|
+
});
|
|
144
147
|
|
|
145
|
-
export const {create, of, make} = factory
|
|
146
|
-
export type Config = z.infer<typeof generatedSchemas.schema
|
|
147
|
-
export type t = Config
|
|
148
|
+
export const { create, of, make } = factory;
|
|
149
|
+
export type Config = z.infer<typeof generatedSchemas.schema>;
|
|
150
|
+
export type t = Config;
|
|
148
151
|
|
|
149
152
|
export const schemas = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
+
...generatedSchemas,
|
|
154
|
+
schema: generatedSchemas.schema.transform(val => val as Config),
|
|
155
|
+
};
|
package/Crypto.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export class Crypto {
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
subtle: SubtleCrypto = crypto.subtle;
|
|
3
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
export const rawSchema = z
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
.string({ description: 'Protocol hash' })
|
|
6
|
+
.refine(
|
|
7
|
+
value => (value.length === 51 && value[0] === 'P' && /[A-Za-z0-9]+/.test(value)),
|
|
8
|
+
value => ({ message: `${value} is an invalid hash for an economical protocol` }),
|
|
9
|
+
);
|
|
10
10
|
|
|
11
|
-
type RawInput = z.infer<typeof rawSchema
|
|
11
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
12
12
|
|
|
13
|
-
export const {schemas: generatedSchemas, factory} = createType<RawInput, RawInput>({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
13
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
14
|
+
rawSchema,
|
|
15
|
+
parseErrMsg: (value: unknown) => `${value} is an invalid economical protocol hash`,
|
|
16
|
+
unknownErrMsg: 'Somethign went wrong trying to parse the economical protocol hash',
|
|
17
|
+
});
|
|
18
18
|
|
|
19
|
-
export type EconomicalPrototypeHash = z.infer<typeof generatedSchemas.schema
|
|
20
|
-
export type t = EconomicalPrototypeHash
|
|
19
|
+
export type EconomicalPrototypeHash = z.infer<typeof generatedSchemas.schema>;
|
|
20
|
+
export type t = EconomicalPrototypeHash;
|
|
21
21
|
|
|
22
|
-
export const {create, of, make} = factory
|
|
22
|
+
export const { create, of, make } = factory;
|
|
23
23
|
export const schemas = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
24
|
+
...generatedSchemas,
|
|
25
|
+
schema: generatedSchemas.schema.transform(val => val as EconomicalPrototypeHash),
|
|
26
|
+
};
|