@taqueria/protocol 0.0.0-pr-786-ffed3033 → 0.0.0-pr-730-90eda834

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 CHANGED
@@ -1,40 +1,38 @@
1
- import {z} from "zod"
2
- import * as Verb from '@taqueria/protocol/Verb'
3
- import * as SingleChar from '@taqueria/protocol/SingleChar'
4
- import createType from "@taqueria/protocol/Base"
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
- .union([
8
- Verb.rawSchema,
9
- SingleChar.rawSchema],
10
- {description: "Alias"}
11
- )
7
+ .union([
8
+ Verb.rawSchema,
9
+ SingleChar.rawSchema,
10
+ ], { description: 'Alias' });
12
11
 
13
12
  export const internalSchema = z
14
- .union([
15
- Verb.schemas.schema,
16
- SingleChar.schemas.schema],
17
- {description: "Alias"}
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
- isStringLike: true,
25
- rawSchema,
26
- internalSchema,
27
- parseErrMsg: (value: unknown) => `${value} is not a valid alias`,
28
- unknownErrMsg: 'Something went wrong trying to parse an alias'
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
- ...generatedSchemas,
39
- schema: generatedSchemas.schema.transform(val => val as Alias)
40
- }
36
+ ...generatedSchemas,
37
+ schema: generatedSchemas.schema.transform(val => val as Alias),
38
+ };
package/Base.ts CHANGED
@@ -1,51 +1,56 @@
1
- import {z, ZodError, ZodSchema} from 'zod'
2
- import {toFutureParseErr, toFutureParseUnknownErr} from "@taqueria/protocol/TaqError"
3
- import {resolve, FutureInstance} from "fluture"
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
- rawSchema: ZodSchema
11
- internalSchema?: ZodSchema
12
- transformer?: (value: unknown) => unknown,
13
- isStringLike?: boolean
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
- parseErrMsg: ErrMsg,
18
- unknownErrMsg: ErrMsg
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
- 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) => transformer(val) as I & {
31
- readonly __kind: "generated" & z.infer<typeof internalSchema>
32
- })
33
- : internalSchema
34
- .transform((val: unknown) => transformer(val) as Flatten<I & {
35
- readonly __kind: "generated" & z.infer<typeof internalSchema>
36
- }>)
37
-
38
- type GeneratedSchema = typeof schema
39
-
40
- return {
41
- rawSchema,
42
- internalSchema,
43
- schema
44
- }
45
- }
46
-
47
-
48
- // TODO:
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
- const schemas = createSchema<I>(params)
57
- const {parseErrMsg, unknownErrMsg} = params
58
-
59
- type T = z.infer<typeof schemas.schema>
60
-
61
- const internalOf = (input: unknown) => {
62
- try {
63
- return resolve<T>(schemas.schema.parse(input))
64
- }
65
- catch (previous) {
66
- const parseMsg = typeof parseErrMsg === 'string'
67
- ? parseErrMsg
68
- : parseErrMsg(input)
69
-
70
- const unknownMsg = typeof unknownErrMsg === 'string'
71
- ? unknownErrMsg
72
- : unknownErrMsg(input)
73
-
74
- if (previous instanceof ZodError) {
75
- return toFutureParseErr<T>(previous, parseMsg, input)
76
- }
77
- return toFutureParseUnknownErr<T>(previous, unknownMsg, input)
78
- }
79
- }
80
- const of = internalOf
81
-
82
- const make = (input: I) => internalOf(input)
83
-
84
- const create = (input: R | I) => schemas.schema.parse(input) as T
85
-
86
- const from = (input: unknown) => schemas.schema.parse(input) as T
87
-
88
- const factory = {
89
- make,
90
- of,
91
- create,
92
- from
93
- }
94
-
95
- return {
96
- schemas,
97
- factory
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 {z} from 'zod'
2
- import createType from "@taqueria/protocol/Base"
1
+ import createType from '@taqueria/protocol/Base';
2
+ import { z } from 'zod';
3
3
 
4
4
  export const rawSchema = z
5
- .string({description: "Command"})
6
- .min(1)
7
- .regex(/^([A-Za-z-_ ]+ ?)((\[.+\] ?)|(\<.+\>) ?)*$/, "Must be a command that can be interpreted using yargs")
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
- 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
- })
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
- ...generatedSchemas,
23
- schema: generatedSchemas.schema.transform(val => val as Command)
24
- }
22
+ ...generatedSchemas,
23
+ schema: generatedSchemas.schema.transform(val => val as Command),
24
+ };
package/Config.ts CHANGED
@@ -1,152 +1,155 @@
1
- import {z} from 'zod'
2
- import * as InstalledPlugin from '@taqueria/protocol/InstalledPlugin'
3
- import * as NetworkConfig from '@taqueria/protocol/NetworkConfig'
4
- import * as SandboxConfig from "@taqueria/protocol/SandboxConfig"
5
- import * as Environment from "@taqueria/protocol/Environment"
6
- import * as Tz from "@taqueria/protocol/Tz"
7
- import createType, {Flatten} from "@taqueria/protocol/Base"
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
- val => val ?? [],
11
- z.array(
12
- InstalledPlugin.rawSchema, {description: "config.plugins"}
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
- val => val ?? [],
18
- z.array(
19
- InstalledPlugin.schemas.schema, {description: "config.plugins"}
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
- .record(
25
- z.union([
26
- NetworkConfig.schemas.schema,
27
- z.string({description: "config.network"})
28
- .nonempty("Default network must reference the name of an existing network configuration.")
29
- ]),
30
- {description: "Network configurations"}
31
- )
32
- .optional()
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
- .record(
36
- z.union([
37
- SandboxConfig.schemas.schema,
38
- z.string({description: "config.sandbox"})
39
- .min(1, "Default sandbox must reference the name of an existing sandbox configuration.")
40
- ]),
41
- {description: "Sandbox configurations"}
42
- )
43
- .optional()
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
- .record(
47
- z.union([
48
- Environment.schemas.schema,
49
- z.string().min(1, "Default environment must reference the name of an existing environment.")
50
- ]),
51
- {description: "Environment configurations"}
52
- )
53
- .optional()
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
- (val: unknown) => val ?? {
57
- "bob": "5_000_000_000",
58
- "alice": "5_000_000_000",
59
- "john": "5_000_000_000",
60
- },
61
- z.record(
62
- z.union([Tz.rawSchema, z.number()]),
63
- {description: "config.accounts"}
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
- language: z.preprocess(
69
- val => val ?? 'en',
70
- z.union([
71
- z.literal('en'),
72
- z.literal('fr')
73
- ], {description: "config.language"})
74
- .optional()
75
- ),
76
- plugins: pluginsInternalSchema.optional(),
77
- contractsDir: z
78
- .preprocess(
79
- (val: unknown) => val ?? "contracts",
80
- z.string({description: "config.contractsDir"})
81
- .min(1, "config.contractsDir must have a value")
82
- ),
83
- artifactsDir: z
84
- .preprocess(
85
- (val: unknown) => val ?? "artifacts",
86
- z.string({description: "config.artifactsDir"})
87
- .min(1, "config.artifactsDir must have a value")
88
- )
89
- }).describe("config")
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
- network: networkMap,
93
- sandbox: sandboxMap,
94
- environment: environmentMap,
95
- accounts: accountsMap
96
- })
95
+ network: networkMap,
96
+ sandbox: sandboxMap,
97
+ environment: environmentMap,
98
+ accounts: accountsMap,
99
+ });
97
100
 
98
101
  export const rawSchema = commonSchema.extend({
99
- plugins: pluginsRawSchema.optional(),
100
- network: z
101
- .record(
102
- z.union([
103
- NetworkConfig.rawSchema,
104
- z.string({description: "config.network"})
105
- .min(1, "Default network must reference the name of an existing network configuration.")
106
- ])
107
- )
108
- .optional(),
109
- sandbox: z
110
- .record(
111
- z.union([
112
- SandboxConfig.rawSchema,
113
- z.string({description: "config.sandbox"})
114
- .min(1, "Default sandbox must reference the name of an existing sandbox configuration.")
115
- ])
116
- )
117
- .optional(),
118
- environment: z
119
- .record(
120
- z.union([
121
- Environment.rawSchema,
122
- z.string({description: "config.environment"})
123
- .min(1, "Default environment must reference the name of an existing environment.")
124
- ])
125
- )
126
- .optional(),
127
- accounts: z
128
- .record(
129
- z.union([Tz.rawSchema, z.number()]),
130
- {description: "config.accounts"}
131
- )
132
- .optional()
133
- }).describe("config")
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
- rawSchema,
140
- internalSchema,
141
- parseErrMsg: (value: unknown) => `${value} is not a configuration`,
142
- unknownErrMsg: "Something went wrong trying to parse your configuration"
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
- ...generatedSchemas,
151
- schema: generatedSchemas.schema.transform(val => val as Config)
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
- subtle: SubtleCrypto = crypto.subtle
3
- }
2
+ subtle: SubtleCrypto = crypto.subtle;
3
+ }
@@ -1,26 +1,26 @@
1
- import {z} from 'zod'
2
- import createType from "@taqueria/protocol/Base"
1
+ import createType from '@taqueria/protocol/Base';
2
+ import { z } from 'zod';
3
3
 
4
4
  export const rawSchema = z
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
- )
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
- 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
- })
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
- ...generatedSchemas,
25
- schema: generatedSchemas.schema.transform(val => val as EconomicalPrototypeHash)
26
- }
24
+ ...generatedSchemas,
25
+ schema: generatedSchemas.schema.transform(val => val as EconomicalPrototypeHash),
26
+ };