@taqueria/protocol 0.0.0-pr-156-6d26c0f4

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # README
2
+
3
+ Provides a shared collection of TypeScript types used in Taqueria.
4
+
5
+ This package is consumed by `taqueria` itself, as well as `taqueria-sdk`.
6
+
7
+ This package can be consumed as an NPM package, and too included as a Deno module.
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@taqueria/protocol",
3
+ "version": "0.0.0-pr-156-6d26c0f4",
4
+ "description": "A TypeScript package which contains types that are to be shared between @taqueria/node-sdk and @taqueria/taqueria.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "echo \"just passing through for CI, no need to build\" && exit 0",
9
+ "prod-config": "echo \"just passing through for CI, no need to update SDK dependency\" && exit 0"
10
+ },
11
+ "keywords": [
12
+ "taqueria",
13
+ "tezos",
14
+ "build",
15
+ "test",
16
+ "deploy",
17
+ "ecad",
18
+ "ecadlabs",
19
+ "protocol"
20
+ ],
21
+ "author": "ECAD Labs",
22
+ "license": "Apache-2.0",
23
+ "bugs": {
24
+ "url": "https://github.com/ecadlabs/taqueria/issues"
25
+ },
26
+ "homepage": "https://github.com/ecadlabs/taqueria#readme",
27
+ "devDependencies": {
28
+ "typescript": "^4.5.4"
29
+ }
30
+ }
@@ -0,0 +1,579 @@
1
+ // TODO - using .ts is necessary for Deno. Explore how to make this
2
+ // consumable by Deno or the TypeScript compiler without any warnings
3
+ // or errors emited
4
+ // @ts-ignore
5
+ import {SanitizedAbsPath, SHA256} from '../taqueria-utils/taqueria-utils-types.ts'
6
+
7
+ /**
8
+ * String-like types
9
+ */
10
+
11
+ export abstract class StringLike {
12
+ readonly value: string
13
+ protected constructor(value: string){
14
+ this.value = value
15
+ }
16
+ static create (value: string) {
17
+ return this.constructor.call(this, value)
18
+ }
19
+ public toString() {
20
+ return this.value
21
+ }
22
+ }
23
+
24
+ const stringMax30Type: unique symbol = Symbol()
25
+ export class StringMax30 extends StringLike {
26
+ [stringMax30Type]: void
27
+ static create(value: string, truncate=false) : StringMax30 | undefined {
28
+ return (value.length <= 30)
29
+ ? new StringMax30(value)
30
+ : (truncate
31
+ ? new StringMax30(value.substr(0, 30))
32
+ : undefined
33
+ )
34
+ }
35
+ }
36
+
37
+ const stringNoSpaces: unique symbol = Symbol()
38
+ export class StringNoSpaces extends StringLike {
39
+ [stringNoSpaces]: void
40
+ static create(value: string) : StringNoSpaces {
41
+ return new StringNoSpaces(value.replace(/\s+/g, '_'))
42
+ }
43
+ }
44
+
45
+ const identiferType: unique symbol = Symbol()
46
+ export class Identifier extends StringLike {
47
+ [identiferType]: void
48
+ static create(value: string): Identifier | undefined {
49
+ const result = StringNoSpaces.create(value).value.match(/^[A-Za-z0-9]+[A-Za-z0-9-_]*$/)
50
+ return result ? new Identifier(result[0]) : undefined
51
+ }
52
+ }
53
+
54
+ const humanReadableIdentifierType: unique symbol = Symbol()
55
+ export class HumanReadableIdentifier extends StringLike {
56
+ [humanReadableIdentifierType]: void
57
+ static create(value: string): HumanReadableIdentifier | undefined {
58
+ const input = StringMax30.create(StringNoSpaces.create(value).value)
59
+ if (input) {
60
+ const result = input.value.match(/^[A-Za-z]+[A-Za-z0-9-_]*$/)
61
+ return result ? new HumanReadableIdentifier(result[0]) : undefined
62
+ }
63
+ return undefined
64
+ }
65
+ }
66
+
67
+ const verbType: unique symbol = Symbol()
68
+ export class Verb extends StringLike {
69
+ [verbType]: void
70
+ static create(value: string): Verb | undefined {
71
+ const result = value.match(/^[A-Za-z\-\ ]+/)
72
+ // TODO - should we do more validation whether its a verb?
73
+ return result ? new Verb(result[0]) : undefined
74
+ }
75
+ }
76
+
77
+ const commandType: unique symbol = Symbol()
78
+ export class Command extends StringLike {
79
+ [commandType]: void
80
+ static create(value: string) : Command | undefined {
81
+ if (value.match(/^([A-Za-z-_ ]+ ?)((\[.+\] ?)|(\<.+\>) ?)*$/)) {
82
+ return new Command(value)
83
+ }
84
+ return undefined
85
+ }
86
+ }
87
+
88
+ const singleChar: unique symbol = Symbol()
89
+ export class SingleChar extends StringLike {
90
+ [singleChar]: void
91
+ static create(value: string): SingleChar | undefined {
92
+ return value && value.toString().match(/^[A-Za-z]/)
93
+ ? new SingleChar(value[0])
94
+ : undefined
95
+ }
96
+ }
97
+
98
+ const urlType: unique symbol = Symbol()
99
+ export class Url {
100
+ [urlType]: void
101
+ readonly url: URL
102
+ private constructor(value: URL) {
103
+ this.url = value
104
+ }
105
+ static create(value: string): Url | undefined {
106
+ try {
107
+ const url = new URL(value)
108
+ return new Url(url)
109
+ }
110
+ catch (_) {
111
+ return undefined
112
+ }
113
+ }
114
+ }
115
+
116
+ export type Alias = Verb | SingleChar
117
+
118
+ /**
119
+ * Types used in the Taqueria Config
120
+ */
121
+
122
+ export interface InstalledPlugin {
123
+ readonly name: string
124
+ readonly type: 'npm' | 'binary' | "deno"
125
+ }
126
+
127
+ export interface Config {
128
+ readonly language?: 'en' | 'fr'
129
+ readonly plugins: InstalledPlugin[]
130
+ readonly contractsDir: string
131
+ readonly testsDir: string
132
+ readonly artifactsDir: string
133
+
134
+ readonly environment: Record<'default'|string, string|EnvironmentConfig>
135
+
136
+ readonly sandbox: Record<string, SandboxConfig>
137
+
138
+ readonly network: Record<string, NetworkConfig>
139
+ }
140
+
141
+ export interface ConfigArgs extends Config {
142
+ projectDir: SanitizedAbsPath,
143
+ configFile: SanitizedAbsPath,
144
+
145
+ hash: SHA256
146
+ }
147
+
148
+ /**
149
+ * Protocol Models
150
+ */
151
+
152
+ export interface UnvalidatedPositionalArg {
153
+ readonly placeholder: string
154
+ readonly type?: OptionType
155
+ readonly defaultValue?: string | number | boolean
156
+ readonly description: string
157
+ }
158
+
159
+
160
+ export interface UnvalidatedOption {
161
+ readonly shortFlag?: string
162
+ readonly flag: string
163
+ readonly description: string
164
+ readonly defaultValue?: string | number | boolean
165
+ readonly choices?: string[]
166
+ readonly required?: boolean
167
+ readonly boolean?: boolean
168
+ }
169
+
170
+ export interface UnvalidatedHook {
171
+ // TODO
172
+ }
173
+
174
+ export interface UnvalidatedScaffold {
175
+ // TODO
176
+ }
177
+
178
+ export interface UnvalidatedNetwork {
179
+ readonly name: string
180
+ readonly label: string
181
+ readonly rpcUrl: string
182
+ readonly protocol: string
183
+ readonly attributes?: Attributes
184
+ }
185
+
186
+ export interface UnvalidatedSandbox extends UnvalidatedNetwork {
187
+ readonly plugin?: string
188
+ readonly accounts?: Record<string, AccountDetails>
189
+ }
190
+
191
+ const hookType: unique symbol = Symbol()
192
+ export class Hook {
193
+ [hookType] : void
194
+ static create(unvalidatedHook: UnvalidatedHook): Hook | undefined {
195
+ return undefined
196
+ }
197
+ }
198
+
199
+ const scaffoldType: unique symbol = Symbol()
200
+ export class Scaffold {
201
+ [scaffoldType] : void
202
+ static create(unvalidatedScaffold: UnvalidatedScaffold): Scaffold | undefined {
203
+ return undefined
204
+ }
205
+ }
206
+
207
+ export type TaskHandler = "proxy" | string | string[]
208
+
209
+
210
+ export interface UnvalidatedTask {
211
+ readonly task: string
212
+ readonly command: string
213
+ readonly description: string
214
+ readonly aliases?: string[]
215
+ readonly options?: (UnvalidatedOption|Option|undefined)[],
216
+ readonly positionals?: (UnvalidatedPositionalArg|undefined|PositionalArg)[]
217
+ readonly handler: "proxy" | string | string[]
218
+ readonly hidden?: boolean
219
+ readonly example?: string
220
+ }
221
+
222
+ export interface UnvalidatedPluginInfo {
223
+ readonly schema: string
224
+ readonly name: string
225
+ readonly alias?: string
226
+ readonly version: string
227
+ readonly tasks?: (UnvalidatedTask|undefined)[]
228
+ readonly scaffolds?: (UnvalidatedScaffold|undefined)[]
229
+ readonly hooks?: (UnvalidatedHook|undefined)[]
230
+ readonly networks?: (UnvalidatedNetwork|undefined)[]
231
+ readonly sandboxes?: (UnvalidatedSandbox|undefined)[]
232
+ }
233
+
234
+ export class PluginInfo {
235
+ readonly schema: string
236
+ readonly name: string
237
+ readonly alias?: string
238
+ readonly version: string
239
+ readonly tasks: Task[]
240
+ readonly scaffolds: Scaffold[]
241
+ readonly hooks: Hook[]
242
+ readonly networks: Network[]
243
+ readonly sandboxes: Sandbox[]
244
+ constructor(schema: string, name: string, version: string, tasks: Task[], scaffolds: Scaffold[], hooks: Hook[], networks: Network[], sandboxes: Sandbox[], alias?: string) {
245
+ this.schema = schema
246
+ this.alias = alias
247
+ this.name = name
248
+ this.version = version
249
+ this.tasks = tasks
250
+ this.scaffolds = scaffolds
251
+ this.hooks = hooks
252
+ this.networks = networks
253
+ this.sandboxes = sandboxes
254
+ }
255
+
256
+ static convert<A, B>(factory: (item: A) => B|undefined) {
257
+ return (obj: UnvalidatedPluginInfo, prop: keyof UnvalidatedPluginInfo) : B[] => obj[prop] ? (obj[prop] as (A|undefined)[]).reduce(
258
+ (retval: B[], unvalidatedItem: A|undefined) => {
259
+ if (unvalidatedItem) {
260
+ try {
261
+ const item = factory(unvalidatedItem)
262
+ return item ? [...retval, item]: retval
263
+ }
264
+ catch (_) {
265
+ return retval
266
+ }
267
+ }
268
+ return retval
269
+ },
270
+ []
271
+ ) : []
272
+ }
273
+
274
+ static create(obj: UnvalidatedPluginInfo) : PluginInfo | undefined {
275
+ if (obj.version && obj.schema) {
276
+ try {
277
+ const createTask = Task.create.bind(Task)
278
+ //TODO: Finish doing the above for each factory/constructor
279
+
280
+ const temp: Record<string, string> = obj.alias
281
+ ? {alias: obj.alias}
282
+ : {}
283
+
284
+ const pluginInfo : PluginInfo = {
285
+ ...temp,
286
+ name: obj.name,
287
+ schema: obj.schema,
288
+ version: obj.version,
289
+ tasks: this.convert<UnvalidatedTask, Task>(createTask) (obj, "tasks"),
290
+ hooks: this.convert(Hook.create) (obj, "hooks"),
291
+ scaffolds: this.convert(Scaffold.create) (obj, "scaffolds"),
292
+ networks: this.convert(Network.create) (obj, "networks"),
293
+ sandboxes: this.convert(Sandbox.create) (obj, "sandboxes")
294
+ }
295
+ return pluginInfo
296
+ }
297
+ catch (_) {
298
+ return undefined
299
+ }
300
+ }
301
+ return undefined
302
+ }
303
+ }
304
+
305
+ export type OptionType = 'string' | 'number' | 'boolean'
306
+
307
+ const positionalArgType: unique symbol = Symbol()
308
+ export class PositionalArg {
309
+ [positionalArgType]: void
310
+ readonly placeholder: HumanReadableIdentifier
311
+ readonly description: string
312
+ readonly defaultValue?: string | number | boolean
313
+ readonly type?: OptionType
314
+
315
+ protected constructor(placeholder: HumanReadableIdentifier, description: string, type?: OptionType, defaultValue?: string | number | boolean) {
316
+ this.placeholder = placeholder
317
+ this.defaultValue = defaultValue
318
+ this.description = description
319
+ this.type = type
320
+ }
321
+
322
+ static create(arg: UnvalidatedPositionalArg) {
323
+ const placeholder = HumanReadableIdentifier.create(arg.placeholder)
324
+ return placeholder
325
+ ? new PositionalArg(placeholder, arg.description, arg.type, arg.defaultValue)
326
+ : undefined
327
+ }
328
+ }
329
+
330
+ const optionType: unique symbol = Symbol()
331
+ export class Option {
332
+ [optionType]: void
333
+ readonly shortFlag?: SingleChar
334
+ readonly flag: Verb
335
+ readonly description: string
336
+ readonly defaultValue?: string | number | boolean
337
+ readonly choices?: string[]
338
+ readonly required?: boolean
339
+ readonly boolean?: boolean
340
+ private constructor(shortFlag: SingleChar | undefined, flag: Verb, description: string, choices: string[], required: boolean, boolean: boolean, defaultValue?: string | number | boolean) {
341
+ this.shortFlag = shortFlag
342
+ this.flag = flag
343
+ this.description = description
344
+ this.defaultValue = defaultValue
345
+ this.required = required
346
+ this.choices = choices
347
+ this.boolean = boolean
348
+ }
349
+ static create(option: UnvalidatedOption): Option | undefined {
350
+ const flag = Verb.create(option.flag)
351
+
352
+ if (!option.shortFlag && flag)
353
+ return new Option(undefined, flag, option.description, option.choices || [], option.required || false, option.boolean ? true : false, option.defaultValue)
354
+
355
+ if (option.shortFlag && flag) {
356
+ const shortFlag = SingleChar.create(option.shortFlag)
357
+ return shortFlag
358
+ ? new Option(shortFlag, flag, option.description, option.choices || [], option.required || false, option.boolean ? true : false, option.defaultValue)
359
+ : undefined
360
+ }
361
+
362
+ return undefined
363
+ }
364
+ }
365
+
366
+ const taskType: unique symbol = Symbol()
367
+ export class Task {
368
+ [taskType]: void
369
+ readonly task: Verb
370
+ readonly command: Command
371
+ readonly aliases: Alias[]
372
+ readonly description: string
373
+ readonly example?: string
374
+ readonly options?: Option[]
375
+ readonly handler: TaskHandler
376
+ readonly hidden: boolean
377
+ readonly positionals: PositionalArg[]
378
+ protected constructor(name: Verb, command: Command, description: string, handler: TaskHandler, options: Option[]=[], positionals: PositionalArg[]=[], aliases: Alias[]=[], hidden=false, example?: string) {
379
+ this.task = name
380
+ this.command = command
381
+ this.description = description
382
+ this.options = options
383
+ this.aliases = aliases
384
+ this.handler = handler
385
+ this.hidden = hidden
386
+ this.example = example
387
+ this.positionals = positionals
388
+ }
389
+ static createAlias(value: string): Alias | undefined {
390
+ return Verb.create(value) || SingleChar.create(value)
391
+ }
392
+
393
+ static create (task: UnvalidatedTask): Task | undefined {
394
+ const name = Verb.create(task.task)
395
+ const command = Command.create(task.command)
396
+ const aliases = task.aliases
397
+ ? task.aliases.reduce(
398
+ (retval: Alias[], unvalidatedAlias) => {
399
+ const alias = this.createAlias(unvalidatedAlias)
400
+ return alias ? [...retval, alias] : retval
401
+ },
402
+ []
403
+ )
404
+ : []
405
+
406
+ const options = !task.options ? [] : task.options.reduce(
407
+ (retval: Option[], option) => {
408
+ if (option instanceof Option) {
409
+ return [...retval, option]
410
+ }
411
+ else if (option === undefined) {
412
+ return retval
413
+ }
414
+ else {
415
+ const validOption = Option.create(option as UnvalidatedOption)
416
+ return validOption ? [...retval, validOption] : retval
417
+ }
418
+ },
419
+ []
420
+ )
421
+
422
+ const positionals = !task.positionals ? [] : task.positionals.reduce(
423
+ (retval: PositionalArg[], item) => {
424
+ if (item instanceof PositionalArg) {
425
+ return [...retval, item]
426
+ }
427
+ else if (item === undefined) {
428
+ return retval
429
+ }
430
+
431
+ const positional = PositionalArg.create(item as UnvalidatedPositionalArg)
432
+ return positional
433
+ ? [...retval, positional]:
434
+ retval
435
+ },
436
+ []
437
+ )
438
+
439
+ return name && command
440
+ ? new Task(name, command, task.description, task.handler, options, positionals, aliases, task.hidden ? true : false, task.example)
441
+ : undefined
442
+ }
443
+ }
444
+
445
+ export interface AccountKeys {
446
+ alias: string
447
+ encryptedKey: string
448
+ publicKey: string
449
+ secretKey: string
450
+ }
451
+
452
+ export interface AccountDetails {
453
+ readonly initialBalance?: string,
454
+ keys?: AccountKeys
455
+ }
456
+
457
+ export interface SandboxConfig {
458
+ readonly label?: string,
459
+ readonly plugin?: string,
460
+ readonly rpcUrl?: string
461
+ readonly protocol?: string
462
+ readonly attributes?: Attributes
463
+ readonly accounts: Record<string|'default', AccountDetails|string>
464
+ }
465
+
466
+ export interface NetworkConfig {
467
+ readonly label?: string,
468
+ readonly rpcUrl?: string
469
+ readonly protocol?: string
470
+ readonly faucet: {
471
+ readonly pkh: string
472
+ readonly mnemonic: string[]
473
+ readonly email: string
474
+ readonly password: string
475
+ readonly amount: string
476
+ readonly activation_code: string
477
+ }
478
+ }
479
+
480
+ export interface EnvironmentConfig {
481
+ readonly networks?: string[]
482
+ readonly sandboxes: string[]
483
+ readonly storage: Record<string, unknown>
484
+ }
485
+
486
+ export interface RuntimeDependency {
487
+ readonly name: string,
488
+ readonly path: string,
489
+ readonly version: string,
490
+ readonly kind: "required" | "optional"
491
+ }
492
+
493
+ export interface Attributes {
494
+ [key: string]: string|number|boolean
495
+ }
496
+
497
+ const economicalPrototypeHashType: unique symbol = Symbol()
498
+ export class EconomicalProtocolHash extends StringLike {
499
+ [economicalPrototypeHashType]: void
500
+ static create(value: string): EconomicalProtocolHash | undefined {
501
+ return value.length === 51 && value[0] === 'P' && /[A-Za-z0-9]+/.test(value)
502
+ ? new EconomicalProtocolHash(value)
503
+ : undefined
504
+ }
505
+ }
506
+
507
+ const economicProtocalType: unique symbol = Symbol()
508
+ export class EconomicalProtocol {
509
+ readonly hash: EconomicalProtocolHash
510
+ readonly label: HumanReadableIdentifier | undefined
511
+ constructor(hash: EconomicalProtocolHash, label: (HumanReadableIdentifier|undefined)=undefined) {
512
+ this.hash = hash
513
+ this.label = label
514
+ }
515
+ static create(hash: string, label: (string|undefined)=undefined) {
516
+ const validHash = EconomicalProtocolHash.create(hash)
517
+ const validLabel = label ? HumanReadableIdentifier.create(label) : undefined
518
+ return validHash
519
+ ? new EconomicalProtocol(validHash, validLabel)
520
+ : undefined
521
+ }
522
+ }
523
+
524
+ const networkType: unique symbol = Symbol()
525
+ export class Network {
526
+ [networkType]: void
527
+ readonly name: HumanReadableIdentifier
528
+ readonly label: StringMax30
529
+ readonly rpcUrl: Url
530
+ readonly protocol: EconomicalProtocol
531
+ readonly attributes: Attributes
532
+ public constructor (name: HumanReadableIdentifier, label: StringMax30, rpcUrl: Url, protocol: EconomicalProtocol, attributes: Attributes) {
533
+ this.name = name
534
+ this.label = label
535
+ this.rpcUrl = rpcUrl
536
+ this.protocol = protocol
537
+ this.attributes = attributes
538
+ }
539
+
540
+ static create(network : UnvalidatedNetwork) {
541
+ const validName = HumanReadableIdentifier.create(network.name)
542
+ const validLabel = StringMax30.create(network.label)
543
+ const validUrl = Url.create(network.rpcUrl)
544
+ const validProto = EconomicalProtocol.create(network.protocol)
545
+
546
+ return validName && validLabel && validUrl && validProto
547
+ ? new Network(validName, validLabel, validUrl, validProto, network.attributes ? network.attributes : {})
548
+ : undefined
549
+ }
550
+ }
551
+
552
+ const sandboxType: unique symbol = Symbol()
553
+ export class Sandbox extends Network {
554
+ readonly accounts: Record<string, AccountDetails>
555
+ [sandboxType]: void
556
+ readonly plugin?: string
557
+
558
+ protected constructor(name: HumanReadableIdentifier, label: StringMax30, rpcUrl: Url, protocol: EconomicalProtocol, attributes: Attributes, plugin?: string, accounts?: Record<string, AccountDetails>) {
559
+ super(name, label, rpcUrl, protocol, attributes)
560
+ this.plugin = plugin
561
+ this.accounts = accounts ? accounts: {}
562
+ }
563
+
564
+ static create(sandbox: UnvalidatedSandbox) {
565
+ const network = super.create(sandbox)
566
+ return network
567
+ ? new Sandbox(network.name, network.label, network.rpcUrl, network.protocol, network.attributes, sandbox.plugin, sandbox.accounts)
568
+ : undefined
569
+ }
570
+ }
571
+
572
+ export interface Environment {
573
+ readonly name: string
574
+ readonly networks?: Network[]
575
+ readonly sandboxes?: Sandbox[]
576
+ readonly storage: Record<string, unknown>
577
+ }
578
+
579
+ export type Action = "checkRuntimeDependencies" | "installRuntimeDependencies" | "proxy" | "pluginInfo" | string