@taqueria/protocol 0.0.0-pr-436-0c8bb7b1 → 0.0.0-pr-659-ec26fd9f

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 ADDED
@@ -0,0 +1,34 @@
1
+ import {z, ZodError} from "zod"
2
+ import * as Verb from '@taqueria/protocol/Verb'
3
+ import * as SingleChar from '@taqueria/protocol/SingleChar'
4
+ import {resolve, reject} from "fluture"
5
+ import {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
6
+
7
+ export const internalSchema = z
8
+ .union([Verb.schema, SingleChar.schema], {description: "Alias"})
9
+
10
+ export const rawSchema = z
11
+ .union([Verb.rawSchema, SingleChar.rawSchema], {description: "Alias"})
12
+
13
+ const aliasType: unique symbol = Symbol("Alias")
14
+
15
+ export type Alias = string & {
16
+ readonly [aliasType]: void
17
+ }
18
+
19
+ export type t = Alias
20
+
21
+ export const schema = internalSchema.transform((val: unknown) => val as Alias)
22
+
23
+ export const make = (value: string) => {
24
+ try {
25
+ const alias = schema.parse(value)
26
+ return resolve(alias)
27
+ }
28
+ catch (err) {
29
+ if (err instanceof ZodError) {
30
+ return toParseErr<Alias>(err, `${value} is not a valid alias`, value)
31
+ }
32
+ return toParseUnknownErr<Alias>(err, 'Something went wrong trying to parse an alias', value)
33
+ }
34
+ }
package/Command.ts ADDED
@@ -0,0 +1,33 @@
1
+ import {z, ZodError} from 'zod'
2
+ import {resolve, reject, mapRej} from "fluture"
3
+ import {TaqError, toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
4
+
5
+ export const rawSchema = z
6
+ .string({description: "Command"})
7
+ .regex(/^([A-Za-z-_ ]+ ?)((\[.+\] ?)|(\<.+\>) ?)*$/, "Must be a command that can be interpreted using yargs")
8
+
9
+ export const schema = rawSchema.transform(val => val as Command)
10
+
11
+ const commandType: unique symbol = Symbol("Command")
12
+
13
+ export type Command = string & {
14
+ readonly [commandType]: void
15
+ }
16
+
17
+ export type t = Command
18
+
19
+ export const make = (value: string) => {
20
+ try {
21
+ const retval = schema.parse(value)
22
+ return resolve(retval)
23
+ .pipe(mapRej(err => err as TaqError))
24
+ }
25
+ catch (err) {
26
+ if (err instanceof ZodError) {
27
+ return toParseErr<Command>(err, `${value} is not a valid command`, value)
28
+ }
29
+ return toParseUnknownErr<Command>(err, 'There was a problem trying to parse the command', value)
30
+ }
31
+ }
32
+
33
+ export const create = (value: string) => schema.parse(value)
package/Config.ts ADDED
@@ -0,0 +1,168 @@
1
+ import {z, ZodError} 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 {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
8
+ import {resolve, reject} from "fluture"
9
+
10
+ const networkMap = z
11
+ .record(
12
+ z.union([
13
+ NetworkConfig.schema,
14
+ z.string({description: "config.network"})
15
+ .nonempty("Default network must reference the name of an existing network configuration.")
16
+ ]),
17
+ {description: "Network configurations"}
18
+ )
19
+ .optional()
20
+
21
+ const sandboxMap = z
22
+ .record(
23
+ z.union([
24
+ SandboxConfig.schema,
25
+ z.string({description: "config.sandbox"})
26
+ .nonempty("Default sandbox must reference the name of an existing sandbox configuration.")
27
+ ]),
28
+ {description: "Sandbox configurations"}
29
+ )
30
+ .optional()
31
+
32
+ const environmentMap = z
33
+ .record(
34
+ z.union([
35
+ Environment.schema,
36
+ z.string({description: "config.environment"})
37
+ .nonempty("Default environment must reference the name of an existing environment.")
38
+ ]),
39
+ {description: "Environment configurations"}
40
+ )
41
+ .optional()
42
+
43
+ const accountsMap = z.preprocess(
44
+ (val: unknown) => val ?? {
45
+ "bob": "5_000_000_000",
46
+ "alice": "5_000_000_000",
47
+ "john": "5_000_000_000",
48
+ },
49
+ z.record(
50
+ z.union([Tz.rawSchema, z.number()]),
51
+ {description: "config.accounts"}
52
+ )
53
+ )
54
+
55
+ const commonSchema = z.object({
56
+ language: z
57
+ .union([z.literal('en'), z.literal('fr')], {description: "config.language"})
58
+ .optional()
59
+ .transform((val?: 'en' | 'fr' | string) => val ?? 'en'),
60
+ plugins: z
61
+ .array(InstalledPlugin.schema, {description: "config.plugins"})
62
+ .optional()
63
+ .transform((val: unknown) => val ?? ([] as InstalledPlugin.t[])),
64
+ testsDir: z
65
+ .preprocess(
66
+ (val: unknown) => val ?? "tests",
67
+ z.string({description: "config.testsDir"})
68
+ .nonempty("config.testsDir must have a value")
69
+ .optional()
70
+ ),
71
+ contractsDir: z
72
+ .preprocess(
73
+ (val: unknown) => val ?? "contracts",
74
+ z.string({description: "config.contractsDir"})
75
+ .nonempty("config.contractsDir must have a value")
76
+ .optional()
77
+ ),
78
+ artifactsDir: z
79
+ .preprocess(
80
+ (val: unknown) => val ?? "artifacts",
81
+ z.string({description: "config.artifactsDir"})
82
+ .nonempty("config.artifactsDir must have a value")
83
+ .optional()
84
+ ),
85
+ operationsDir: z
86
+ .preprocess(
87
+ (val: unknown) => val ?? "operations",
88
+ z.string({description: "config.operationsDir"})
89
+ .nonempty("config.operationsDir must have a value")
90
+ .optional()
91
+ )
92
+ }).describe("config")
93
+
94
+ export const internalSchema = commonSchema.extend({
95
+ network: networkMap,
96
+ sandbox: sandboxMap,
97
+ environment: environmentMap,
98
+ accounts: accountsMap
99
+ })
100
+
101
+ export const rawSchema = commonSchema.extend({
102
+ network: z
103
+ .record(
104
+ z.union([
105
+ NetworkConfig.rawSchema,
106
+ z.string({description: "config.network"})
107
+ .nonempty("Default network must reference the name of an existing network configuration.")
108
+ ])
109
+ )
110
+ .optional(),
111
+ sandbox: z
112
+ .record(
113
+ z.union([
114
+ SandboxConfig.rawSchema,
115
+ z.string({description: "config.sandbox"})
116
+ .nonempty("Default sandbox must reference the name of an existing sandbox configuration.")
117
+ ])
118
+ )
119
+ .optional(),
120
+ environment: z
121
+ .record(
122
+ z.union([
123
+ Environment.rawSchema,
124
+ z.string({description: "config.environment"})
125
+ .nonempty("Default environment must reference the name of an existing environment.")
126
+ ])
127
+ )
128
+ .optional(),
129
+ accounts: z
130
+ .record(
131
+ z.union([Tz.rawSchema, z.number()]),
132
+ {description: "config.accounts"}
133
+ )
134
+ .optional()
135
+ }).describe("config")
136
+
137
+ export const schema = internalSchema.transform((val: unknown) => val as t)
138
+
139
+ const configType: unique symbol = Symbol("Config")
140
+
141
+ type Input = z.infer<typeof internalSchema>
142
+
143
+ type RawInput = z.infer<typeof rawSchema>
144
+
145
+ export type t = Input & {
146
+ readonly [configType]: void
147
+ readonly contractsDir: string
148
+ readonly artifactsDir: string
149
+ readonly testsDir: string
150
+ readonly plugins: InstalledPlugin.t[]
151
+ }
152
+
153
+ export type Config = t
154
+
155
+ export const make = (data: Input) => {
156
+ try {
157
+ const retval = schema.parse(data)
158
+ return resolve(retval)
159
+ }
160
+ catch (err) {
161
+ if (err instanceof ZodError) {
162
+ return toParseErr<Config>(err, `The provided config is invalid.`, data)
163
+ }
164
+ return toParseUnknownErr<Config>(err, 'There was a problem trying to parse the Taqueria configuration', data)
165
+ }
166
+ }
167
+
168
+ export const create = (data: RawInput | Record<string, unknown>) => schema.parse(data)
package/Crypto.ts ADDED
@@ -0,0 +1,3 @@
1
+ export class Crypto {
2
+ subtle: SubtleCrypto = crypto.subtle
3
+ }
@@ -0,0 +1,32 @@
1
+ import {z, ZodError} from 'zod'
2
+ import {resolve, reject} from "fluture"
3
+ import {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
4
+
5
+ const protocolHashType: unique symbol = Symbol("EconomicalProtocolHash")
6
+
7
+ export const schema = z
8
+ .string({description: "Protocol hash"})
9
+ .refine(
10
+ value => (value.length === 51 && value[0] === 'P' && /[A-Za-z0-9]+/.test(value)),
11
+ value => ({message: `${value} is an invalid hash for an economical protocol`})
12
+ )
13
+ .transform(val => val as EconomicalProtocolHash)
14
+
15
+ export type EconomicalProtocolHash = string & {
16
+ readonly [protocolHashType]: void
17
+ }
18
+
19
+ export type t = EconomicalProtocolHash
20
+
21
+ export const make = (value: string) => {
22
+ try {
23
+ const retval = schema.parse(value)
24
+ return resolve(retval)
25
+ }
26
+ catch (err) {
27
+ if (err instanceof ZodError) {
28
+ return toParseErr<EconomicalProtocolHash>(err, `${value} is not a valid economical protocol hash`, value)
29
+ }
30
+ return toParseUnknownErr<EconomicalProtocolHash>(err, "There was a problem trying to parse the economical protocol", value)
31
+ }
32
+ }
package/Environment.ts ADDED
@@ -0,0 +1,44 @@
1
+ import {z, ZodError} from 'zod'
2
+ import {reject, resolve} from "fluture"
3
+ import {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
4
+
5
+ export const rawSchema = z.object({
6
+ networks: z.array(
7
+ z.string({description: "Environment network"})
8
+ .nonempty("Must reference the name of an existing network configuration")
9
+ ),
10
+ sandboxes: z.array(
11
+ z.string({description: "Environment sandbox"})
12
+ .nonempty("Must reference the name of an existing sandbox configuration")
13
+ ),
14
+ storage: z.record(
15
+ z.any({description: "Environment storage value"}),
16
+ {description: "Environment storage"}
17
+ )
18
+ .optional()
19
+ }).describe("Environment Config")
20
+
21
+ export const schema = rawSchema.transform(val => val as Environment)
22
+
23
+ const envType: unique symbol = Symbol("Environment")
24
+
25
+ type Input = z.infer<typeof rawSchema>
26
+
27
+ export type Environment = Input & {
28
+ readonly [envType]: void
29
+ }
30
+
31
+ export type t = Environment
32
+
33
+ export const make = (value: Input) => {
34
+ try {
35
+ const retval = schema.parse(value)
36
+ return resolve(retval)
37
+ }
38
+ catch (err) {
39
+ if (err instanceof ZodError) {
40
+ return toParseErr<Environment>(err, `The provided environment is invalid`, value)
41
+ }
42
+ return toParseUnknownErr<Environment>(err, "There was a problem trying to parse the environment configuration", value)
43
+ }
44
+ }
@@ -0,0 +1,209 @@
1
+ import {z, ZodError} from 'zod'
2
+ import {FutureInstance as Future, resolve, mapRej, attemptP, promise} from "fluture"
3
+ import {TaqError, toParseErr, toParseUnknownErr, E_TaqError} from "@taqueria/protocol/TaqError"
4
+ import * as InstalledPlugin from "@taqueria/protocol/InstalledPlugin"
5
+ import * as Command from "@taqueria/protocol/Command"
6
+ import * as Option from '@taqueria/protocol/Option'
7
+ import * as Verb from "@taqueria/protocol/Verb"
8
+ import * as Task from '@taqueria/protocol/Task'
9
+ import * as ParsedOperation from '@taqueria/protocol/ParsedOperation'
10
+ import * as ParsedPluginInfo from '@taqueria/protocol/ParsedPluginInfo'
11
+ import * as Config from "@taqueria/protocol/Config"
12
+ import type {i18n} from "@taqueria/protocol/i18n"
13
+
14
+ const eager = <T>(f: Future<TaqError, T>) => promise (
15
+ mapRej
16
+ ((err: TaqError) => new E_TaqError(err))
17
+ (f)
18
+ )
19
+
20
+ const taskToPluginMap = z.record(
21
+ z.union([
22
+ InstalledPlugin.schema,
23
+ Task.schema
24
+ ], {description: "Task/Plugin Mapping"})
25
+ )
26
+ const operationToPluginMap = z.record(
27
+ z.union([
28
+ InstalledPlugin.schema,
29
+ ParsedOperation.schema
30
+ ], {description: "Operation/Plugin Mapping"})
31
+ )
32
+
33
+ const internalSchema = z.object({
34
+ build: z.string({description: "cache.build"}),
35
+ configHash: z.string({description: "cache.configHash"}),
36
+ tasks: taskToPluginMap,
37
+ operations: operationToPluginMap,
38
+ plugins: z.array(ParsedPluginInfo.schema, {description: "cache.plugins"})
39
+ }).describe("Ephermal State")
40
+
41
+ export const schema = internalSchema.transform(val => val as EphemeralState)
42
+
43
+ const ephemeralStateType: unique symbol = Symbol("EphemeralState")
44
+
45
+ export type Input = z.infer<typeof internalSchema>
46
+
47
+ export type EphemeralState = Input & {
48
+ readonly [ephemeralStateType]: void
49
+ }
50
+
51
+ export type t = EphemeralState
52
+
53
+ export type TaskToPluginMap = z.infer<typeof taskToPluginMap>
54
+
55
+ export type OpToPluginMap = z.infer<typeof operationToPluginMap>
56
+
57
+ export const make = (value: Input) => {
58
+ try {
59
+ const retval = schema.parse(value)
60
+ return resolve(retval)
61
+ }
62
+ catch (err) {
63
+ if (err instanceof ZodError) {
64
+ return toParseErr<EphemeralState>(err, `The ephermal state is invalid`, value)
65
+ }
66
+ return toParseUnknownErr<EphemeralState>(err, `Something went wrong trying to parse the ephermal state`, value)
67
+ }
68
+ }
69
+
70
+
71
+ /**
72
+ * Private functions
73
+ */
74
+ type Counts = Record<Verb.t, ParsedPluginInfo.t[]>
75
+ const getTaskCounts = (pluginInfo: ParsedPluginInfo.t[]): Counts => {
76
+ return pluginInfo.reduce(
77
+ (retval, pluginInfo) => pluginInfo.tasks === undefined
78
+ ? {}
79
+ : pluginInfo.tasks.reduce(
80
+ (retval: Counts, task: Task.t) => {
81
+ const taskName = task.task
82
+ const providers: ParsedPluginInfo.t[] = retval[taskName]
83
+ ? [...retval[taskName], pluginInfo]
84
+ : [pluginInfo]
85
+ const mapping: Counts = {}
86
+ mapping[taskName] = providers.filter(provider => provider !== undefined)
87
+ return {...retval, ...mapping}
88
+ },
89
+ retval
90
+ ),
91
+ ({} as Counts)
92
+ )
93
+ }
94
+
95
+
96
+ const getOperationCounts = (pluginInfo: ParsedPluginInfo.t[]): Counts => {
97
+ return pluginInfo.reduce(
98
+ (retval, pluginInfo) => pluginInfo.operations === undefined
99
+ ? retval
100
+ : pluginInfo.operations.reduce(
101
+ (retval: Counts, operation: ParsedOperation.t) => {
102
+ const operationName = operation.operation
103
+ const providers = retval[operationName]
104
+ ? [...retval[operationName], pluginInfo]
105
+ : [pluginInfo]
106
+ const mapping: Counts = {}
107
+ mapping[operationName] = providers.filter(provider => provider !== undefined)
108
+ return {...retval, ...mapping}
109
+ },
110
+ retval
111
+ ),
112
+ {} as Counts
113
+ )
114
+ }
115
+
116
+ const toChoices = (plugins: ParsedPluginInfo.t[]) => plugins.reduce(
117
+ (retval, pluginInfo) => {
118
+ return [...retval, pluginInfo.name as string, pluginInfo.alias as string]
119
+ },
120
+ [] as string[]
121
+ )
122
+
123
+ const isComposite = (name: Verb.t, counts: Counts) => counts[name].length > 1
124
+
125
+ const getInstalledPlugin = (config: Config.t, name: string) => config.plugins?.find(
126
+ (plugin: InstalledPlugin.t) => [`taqueria-plugin-${name}`, name].includes(plugin.name)
127
+ )
128
+
129
+
130
+ export const mapTasksToPlugins = (config: Config.t, pluginInfo: ParsedPluginInfo.t[], i18n: i18n) => {
131
+ const taskCounts = getTaskCounts(pluginInfo)
132
+ return attemptP<TaqError, TaskToPluginMap>(async () => await pluginInfo.reduce(
133
+ async (retval, pluginInfo) => !pluginInfo.tasks
134
+ ? Promise.resolve({} as TaskToPluginMap)
135
+ : await pluginInfo.tasks.reduce(
136
+ async (retval, {task}) => {
137
+ if (isComposite(task, taskCounts)) {
138
+ const command = await eager (Command.make(task))
139
+ const compositeTask = await eager (Task.make({
140
+ task,
141
+ command,
142
+ description: i18n.__("providedByMany"),
143
+ hidden: false,
144
+ options: [
145
+ await eager (Option.make({
146
+ flag: await eager (Verb.make("plugin")),
147
+ description: "Specify which plugin should be used to execute this task",
148
+ choices: toChoices(taskCounts[task]),
149
+ required: true
150
+ }))
151
+ ],
152
+ handler: "proxy"
153
+ }))
154
+ return {...await retval, [task]: compositeTask}
155
+ }
156
+
157
+ // Task is provided by just a single plugin
158
+ const installedPlugin = getInstalledPlugin(config, pluginInfo.name)
159
+ return installedPlugin
160
+ ? {...await retval, [task]: installedPlugin}
161
+ : retval
162
+ },
163
+ retval
164
+ ),
165
+ Promise.resolve({} as TaskToPluginMap)
166
+ )).pipe(mapRej (rej => rej as TaqError))
167
+ }
168
+
169
+ export const mapOperationsToPlugins = (config: Config.t, pluginInfo: ParsedPluginInfo.t[], i18n: i18n) => {
170
+ const opCounts = getOperationCounts(pluginInfo)
171
+ return attemptP(async () => await pluginInfo.reduce(
172
+ async (retval, pluginInfo) => !pluginInfo.operations
173
+ ? Promise.resolve({} as OpToPluginMap)
174
+ : await pluginInfo.operations.reduce(
175
+ async (retval, {operation}) => {
176
+ if (isComposite(operation, opCounts)) {
177
+ const command = await eager (Command.make(operation))
178
+ const compositeOp = await eager (ParsedOperation.make({
179
+ operation,
180
+ command,
181
+ description: i18n.__("providedByMany"),
182
+ options: [
183
+ await eager (Option.make({
184
+ flag: await eager (Verb.make("plugin")),
185
+ description: "Specify which plugin should be used to execute this operation",
186
+ choices: toChoices(opCounts[operation]),
187
+ required: true
188
+ }))
189
+ ]
190
+ }))
191
+ return {...await retval, [operation]: compositeOp}
192
+ }
193
+
194
+ // Operation is provided by just a single plugin
195
+ const installedPlugin = getInstalledPlugin(config, pluginInfo.name)
196
+ return installedPlugin
197
+ ? {...await retval, [operation]: installedPlugin}
198
+ : retval
199
+ },
200
+ retval
201
+ ),
202
+ Promise.resolve({} as OpToPluginMap)
203
+ )).pipe(mapRej (rej => rej as TaqError))
204
+ }
205
+
206
+ export const getTasks = (pluginInfo: ParsedPluginInfo.t[]) => pluginInfo.reduce(
207
+ (retval: Task.t[], pluginInfo) => [...retval, ...(pluginInfo.tasks ?? [])],
208
+ []
209
+ )
package/Faucet.ts ADDED
@@ -0,0 +1,57 @@
1
+ import {z, ZodError} from 'zod'
2
+ import * as PublicKeyHash from "@taqueria/protocol/PublicKeyHash"
3
+ import {resolve, reject} from 'fluture'
4
+ import {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
5
+
6
+ const internalSchema = z.object({
7
+ pkh: PublicKeyHash.schema,
8
+ mnemonic: z.array(
9
+ z.string({description: "Faucet Mnemonic Word"}).nonempty().regex(/^[a-z]{2,}$/),
10
+ {description: "Faucet Mnemonic"}
11
+ ),
12
+ email: z.string({description: "Faucet E-mail"}).regex(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/),
13
+ password: z.string({description: "Faucet Password"}).nonempty(),
14
+ amount: z.string({description: "Faucet Account"}).nonempty().regex(/^\d+$/),
15
+ activation_code: z.string({description: "Faucet Activation Code"}).nonempty()
16
+ }).describe("Faucet")
17
+
18
+ export const rawSchema = z.object({
19
+ pkh: z.string({description: "Faucet Public Key Hash"}).nonempty(),
20
+ mnemonic: z.array(
21
+ z.string({description: "Faucet Mnemonic Word"}).nonempty(),
22
+ {description: "Faucet Mnemonic"}
23
+ ),
24
+ email: z.string({description: "Faucet E-mail"}).regex(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/),
25
+ password: z.string({description: "Faucet Password"}).nonempty(),
26
+ amount: z.string({description: "Faucet Account"}).nonempty().regex(/^\d+$/),
27
+ activation_code: z.string({description: "Faucet Activation Code"}).nonempty()
28
+ }).describe("Faucet")
29
+
30
+ export const schema = internalSchema.transform(val => val as Faucet)
31
+
32
+ type Input = z.infer<typeof internalSchema>
33
+
34
+ type RawInput = z.infer<typeof rawSchema>
35
+
36
+ const faucetType: unique symbol = Symbol("Faucet")
37
+
38
+ export type Faucet = Input & {
39
+ readonly [faucetType]: void
40
+ }
41
+
42
+ export type t = Faucet
43
+
44
+ export const make = (data: Input) => {
45
+ try {
46
+ const retval = schema.parse(data)
47
+ return resolve(retval)
48
+ }
49
+ catch (err) {
50
+ if (err instanceof ZodError) {
51
+ return toParseErr<Faucet>(err, `The provided faucet is invalid.`, data)
52
+ }
53
+ return toParseUnknownErr<Faucet>(err, "There was a problem trying to parse the faucet configuration", data)
54
+ }
55
+ }
56
+
57
+ export const create = (data: RawInput) => schema.parse(data)
@@ -0,0 +1,30 @@
1
+ import {z, ZodError} from 'zod'
2
+ import {resolve, reject} from 'fluture'
3
+ import {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
4
+
5
+ export const rawSchema = z
6
+ .string({description: "Human Readable Identifier"})
7
+ .regex(/^[A-Za-z]+[A-Za-z0-9-_ ]*$/, "Must be a valid human-readable identifier")
8
+
9
+ export const schema = rawSchema.transform(val => val as t)
10
+
11
+ const hrType: unique symbol = Symbol("HumanReadableIdentifier")
12
+
13
+ export type t = string & {
14
+ readonly [hrType]: void
15
+ }
16
+
17
+ export type HumanReadableIdentifier = t
18
+
19
+ export const make = (value: string) => {
20
+ try {
21
+ const retval = schema.parse(value)
22
+ return resolve(retval)
23
+ }
24
+ catch (err) {
25
+ if (err instanceof ZodError) {
26
+ return toParseErr<HumanReadableIdentifier>(err, `${value} is not a valid identifier`, value)
27
+ }
28
+ return toParseUnknownErr<HumanReadableIdentifier>(err, "There was a problem trying to parse the identifier", value)
29
+ }
30
+ }
@@ -0,0 +1,37 @@
1
+ import {z, ZodError} from 'zod'
2
+ import {resolve} from "fluture"
3
+ import {toParseErr, toParseUnknownErr} from "@taqueria/protocol/TaqError"
4
+
5
+ const installedPluginType: unique symbol = Symbol("InstalledPlugin")
6
+
7
+ const internalSchema = z.object({
8
+ name: z.string({description: "Plugin Name"}).nonempty(),
9
+ type: z.union(
10
+ [z.literal('npm'), z.literal('binary'), z.literal('deno')],
11
+ {description: "Plugin Type"}
12
+ )
13
+ }).describe("InstalledPlugin")
14
+
15
+ export const schema = internalSchema.transform(val => val as InstalledPlugin)
16
+
17
+ type Input = z.infer<typeof internalSchema>
18
+
19
+ export interface InstalledPlugin extends Input {
20
+ readonly [installedPluginType]: void
21
+ }
22
+
23
+ export type t = InstalledPlugin
24
+
25
+
26
+ export const make = (data: Input) => {
27
+ try {
28
+ const retval = schema.parse(data)
29
+ return resolve(retval)
30
+ }
31
+ catch (err) {
32
+ if (err instanceof ZodError) {
33
+ return toParseErr<InstalledPlugin>(err, `The provided plugin is invalid.`, data)
34
+ }
35
+ return toParseUnknownErr<InstalledPlugin>(err, "There was a problem trying to parse an installed plugin", data)
36
+ }
37
+ }