@taqueria/protocol 0.3.0 → 0.4.0-rc2
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 +38 -0
- package/Base.ts +105 -0
- package/Command.ts +24 -0
- package/Config.ts +155 -0
- package/Crypto.ts +3 -0
- package/EconomicalProtocolHash.ts +26 -0
- package/Environment.ts +36 -0
- package/EphemeralState.ts +208 -0
- package/Faucet.ts +46 -0
- package/HumanReadableIdentifier.ts +24 -0
- package/InstalledPlugin.ts +28 -0
- package/LoadedConfig.ts +45 -0
- package/NetworkConfig.ts +39 -0
- package/Operation.ts +70 -0
- package/Option.ts +56 -0
- package/ParsedOperation.ts +33 -0
- package/ParsedPluginInfo.ts +47 -0
- package/PersistentState.ts +67 -0
- package/PluginInfo.ts +67 -0
- package/PositionalArg.ts +49 -0
- package/Provisioner.ts +61 -0
- package/ProvisionerID.ts +25 -0
- package/Provisions.ts +70 -0
- package/PublicKeyHash.ts +28 -0
- package/README.md +87 -3
- package/RequestArgs.ts +76 -0
- package/SHA256.ts +40 -0
- package/SandboxAccountConfig.ts +35 -0
- package/SandboxConfig.ts +63 -0
- package/SanitizedAbsPath.ts +23 -0
- package/SanitizedArgs.ts +154 -0
- package/SanitizedPath.ts +26 -0
- package/SingleChar.ts +23 -0
- package/TaqError.ts +73 -0
- package/Task.ts +71 -0
- package/Timestamp.ts +25 -0
- package/Tz.ts +22 -0
- package/Url.ts +28 -0
- package/Verb.ts +23 -0
- package/VersionNumber.ts +23 -0
- package/i18n.ts +63 -0
- package/package.json +39 -32
- package/taqueria-protocol-types.ts +90 -608
- package/url-join.ts +0 -73
- package/url-parse.ts +0 -150
package/PublicKeyHash.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const rawSchema = z
|
|
5
|
+
.string({ description: 'Public Key Hash' })
|
|
6
|
+
.min(1) // TODO: what's the actual minimum length here?
|
|
7
|
+
.refine(
|
|
8
|
+
val => val.startsWith('tz1'),
|
|
9
|
+
val => ({ message: `${val} is not a valid public key hash` }),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
13
|
+
|
|
14
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
15
|
+
isStringLike: true,
|
|
16
|
+
rawSchema,
|
|
17
|
+
parseErrMsg: (value: unknown) => `${value} is an invalid public key hash`,
|
|
18
|
+
unknownErrMsg: 'Something went wrong parsing the public key hash',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type PublicKeyHash = z.infer<typeof generatedSchemas.schema>;
|
|
22
|
+
export type t = PublicKeyHash;
|
|
23
|
+
export type PKH = PublicKeyHash;
|
|
24
|
+
export const { create, of, make } = factory;
|
|
25
|
+
export const schemas = {
|
|
26
|
+
...generatedSchemas,
|
|
27
|
+
schema: generatedSchemas.schema.transform(val => val as PublicKeyHash),
|
|
28
|
+
};
|
package/README.md
CHANGED
|
@@ -1,7 +1,91 @@
|
|
|
1
1
|
# Taqueria Protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides TypeScript "types" to both the Taqueria CLI and the Taqueria Node SDK.
|
|
4
4
|
|
|
5
|
-
This package is
|
|
5
|
+
This package is consumable in Node and Deno, and therefore care must
|
|
6
|
+
be taken to assure that any changes made to the types do not depend
|
|
7
|
+
solely on a Node or Deno API.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## Zod Types and Schemas
|
|
10
|
+
|
|
11
|
+
Each type is validated using either of the following [Zod](https://github.com/colinhacks/zod#default) schemas:
|
|
12
|
+
|
|
13
|
+
### Raw Schema
|
|
14
|
+
|
|
15
|
+
A schema that parses and _validates_ input using _built-in data types_.
|
|
16
|
+
|
|
17
|
+
### Internal Schema
|
|
18
|
+
|
|
19
|
+
A schema that extends the rawSchema but parses data into custom-defined _concrete types_.
|
|
20
|
+
|
|
21
|
+
### Schema
|
|
22
|
+
|
|
23
|
+
A schema which extends the internalSchema, and _casts_ the data into its custom-defined concrete type
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#### Example:
|
|
27
|
+
|
|
28
|
+
Let's say that we're trying to parse a Person, expecting a JSON object as input. For simplicity, lets say that define a Person with the following shape:
|
|
29
|
+
```
|
|
30
|
+
Person: {
|
|
31
|
+
firstName: Name.t,
|
|
32
|
+
lastName: Name.t
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Both fields are of type Name.t.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Name.t would have a rawSchema that parses input as a string, with a minimum length of 2, and match against a regex to ensure that the string begins with an uppercase letter, and that only alphabetical characters, hyphens, and spaces are allowed. The rawSchema is essentially parsing the input into a built-in type, a string in this case, and validating that the string represents the data expected.
|
|
40
|
+
|
|
41
|
+
The internalSchema of the Name.t type would be the same as the rawSchema in this place, as the rawSchema is parsing the input into a scalar value and simple type, rather than a complex type, such as an object.
|
|
42
|
+
|
|
43
|
+
The schema of the Name.t type would take the value as output from the internalSchema, which would be a validated string in this case, and cast it to a Name.t.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
The _rawSchema_ of a Person.t would parse the input as an object, with two required fields, and would validate those fields using the rawSchema provided by the Name.t type:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
// rawSchema for Person.t
|
|
51
|
+
export const rawSchema = z.object({
|
|
52
|
+
firstName: Name.rawSchema,
|
|
53
|
+
lastName: Name.rawSchema
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The _internalSchema_ extends the rawSchema by parsing the two fields into their proper concrete types:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
// internalSchema for Person.t
|
|
61
|
+
export const internalSchema = z.object({
|
|
62
|
+
firstName: Name.schema,
|
|
63
|
+
lastName: Name.schema
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
Recall that the _schema_ returns a value casted to its appropriate concrete type. Thus, the internalSchema above can be inferred as a Zod Schema with two Name.t fields.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Finally, the _schema_ will cast the object to its own concerete type, Person.t:
|
|
70
|
+
```
|
|
71
|
+
// schema for Person.t
|
|
72
|
+
export const schema = internalSchema.transform(val => val as Person.t)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
#### Factory methods
|
|
77
|
+
|
|
78
|
+
Each type module has the following methods which map input to a parsed value of it's associated type:
|
|
79
|
+
- `make()` - accepts a value as input that can be inferred to a type represented by the internalSchema. Returns a `Future<TaqError, T>`. Should be used internally by the CLI
|
|
80
|
+
- `create()` - accepts a value as input with an unknown shape. Throws on failure. Should be used by plugin authors, not internally in the CLI.
|
|
81
|
+
- `of()` - accepts a value as input with an unknown shape. Returns a `Future<TaqError, T>`. Typically used by the CLI when parsing input from files such as config.json.
|
|
82
|
+
|
|
83
|
+
## Tips
|
|
84
|
+
|
|
85
|
+
Zod schemas expose a default() method. This doesn't work well when the optional() method is used as well. As such, please use the transform() method to set default values.
|
|
86
|
+
|
|
87
|
+
E.g.
|
|
88
|
+
|
|
89
|
+
Instead of this: `z.string().default('contracts').optional()`
|
|
90
|
+
|
|
91
|
+
Use this: `z.string().optional().transform(val => val ?? 'contracts')`
|
package/RequestArgs.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import * as LoadedConfig from '@taqueria/protocol/LoadedConfig';
|
|
3
|
+
import { rawSchema as sanitizedArgsSchema } from '@taqueria/protocol/SanitizedArgs';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
const rawSchema = sanitizedArgsSchema.extend({
|
|
7
|
+
taqRun: z.union([
|
|
8
|
+
z.literal('pluginInfo'),
|
|
9
|
+
z.literal('proxy'),
|
|
10
|
+
z.literal('checkRuntimeDependencies'),
|
|
11
|
+
z.literal('installRuntimeDependencies'),
|
|
12
|
+
], { description: 'request.taq_run' }),
|
|
13
|
+
config: z.preprocess(
|
|
14
|
+
val => typeof val === 'string' ? JSON.parse(val) : val,
|
|
15
|
+
LoadedConfig.rawSchema,
|
|
16
|
+
),
|
|
17
|
+
}).describe('RequestArgs').passthrough();
|
|
18
|
+
|
|
19
|
+
const internalSchema = sanitizedArgsSchema.extend({
|
|
20
|
+
taqRun: z.union([
|
|
21
|
+
z.literal('pluginInfo'),
|
|
22
|
+
z.literal('proxy'),
|
|
23
|
+
z.literal('checkRuntimeDependencies'),
|
|
24
|
+
z.literal('installRuntimeDependencies'),
|
|
25
|
+
], { description: 'request.taq_run' }),
|
|
26
|
+
config: z.preprocess(
|
|
27
|
+
val => typeof val === 'string' ? JSON.parse(val) : val,
|
|
28
|
+
LoadedConfig.schemas.schema,
|
|
29
|
+
),
|
|
30
|
+
}).describe('RequestArgs').passthrough();
|
|
31
|
+
|
|
32
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
33
|
+
type Input = z.infer<typeof internalSchema>;
|
|
34
|
+
|
|
35
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
|
|
36
|
+
rawSchema,
|
|
37
|
+
internalSchema,
|
|
38
|
+
parseErrMsg: 'The request is invalid',
|
|
39
|
+
unknownErrMsg: 'Something went wrong trying to parse the request',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export type RequestArgs = z.infer<typeof generatedSchemas.schema>;
|
|
43
|
+
export type t = RequestArgs;
|
|
44
|
+
|
|
45
|
+
export const schemas = {
|
|
46
|
+
...generatedSchemas,
|
|
47
|
+
schema: generatedSchemas.schema.transform(val => val as RequestArgs),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const rawProxySchema = rawSchema.extend({
|
|
51
|
+
task: z.string().min(1),
|
|
52
|
+
}).describe('ProxyRequestArgs').passthrough();
|
|
53
|
+
|
|
54
|
+
const internalProxySchema = internalSchema.extend({
|
|
55
|
+
task: z.string().min(1),
|
|
56
|
+
}).describe('ProxyRequestArgs').passthrough();
|
|
57
|
+
|
|
58
|
+
type RawProxyInput = z.infer<typeof rawProxySchema>;
|
|
59
|
+
type ProxyInput = z.infer<typeof internalProxySchema>;
|
|
60
|
+
|
|
61
|
+
export const proxy = createType<RawProxyInput, ProxyInput>({
|
|
62
|
+
rawSchema: rawProxySchema,
|
|
63
|
+
internalSchema: internalProxySchema,
|
|
64
|
+
parseErrMsg: 'The request is invalid',
|
|
65
|
+
unknownErrMsg: 'Something went wrong trying to parse the request',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export const proxySchemas = proxy.schemas;
|
|
69
|
+
export const proxyFactory = proxy.factory;
|
|
70
|
+
|
|
71
|
+
export type ProxyRequestArgs = z.infer<typeof proxySchemas.schema>;
|
|
72
|
+
|
|
73
|
+
export const createProxyRequestArgs = proxyFactory.from;
|
|
74
|
+
export const makeProxyRequestArgs = proxyFactory.make;
|
|
75
|
+
export const ofProxyRequestArgs = proxyFactory.of;
|
|
76
|
+
export const { create, make, of, from } = factory;
|
package/SHA256.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Crypto } from '@peculiar/webcrypto';
|
|
2
|
+
import createType from '@taqueria/protocol/Base';
|
|
3
|
+
import { E_TaqError, TaqError } from '@taqueria/protocol/TaqError';
|
|
4
|
+
import { FutureInstance as Future, mapRej, promise } from 'fluture';
|
|
5
|
+
import { TextEncoder } from 'util';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
const eager = <T>(f: Future<TaqError, T>) =>
|
|
9
|
+
promise(
|
|
10
|
+
mapRej((err: TaqError) => new E_TaqError(err))(f),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const rawSchema = z.string({ description: 'SHA256' }).length(64);
|
|
14
|
+
|
|
15
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
16
|
+
|
|
17
|
+
const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
18
|
+
isStringLike: true,
|
|
19
|
+
rawSchema,
|
|
20
|
+
parseErrMsg: (value: unknown) => `${value} is an invalid SHA256 hash`,
|
|
21
|
+
unknownErrMsg: (value: unknown) => `Something went wrong trying to parse the following as a SHA256 value, ${value}`,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const toSHA256 = async (value: string) => {
|
|
25
|
+
const encoder = new TextEncoder();
|
|
26
|
+
const data = encoder.encode(value);
|
|
27
|
+
const crypto = new Crypto();
|
|
28
|
+
const hash = await crypto.subtle.digest('SHA-256', data);
|
|
29
|
+
const hashArray = Array.from(new Uint8Array(hash)); // convert buffer to byte array
|
|
30
|
+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
31
|
+
return eager(factory.make(hashHex));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type SHA256 = z.infer<typeof generatedSchemas.schema>;
|
|
35
|
+
export type t = SHA256;
|
|
36
|
+
export const { create, of, make } = factory;
|
|
37
|
+
export const schemas = {
|
|
38
|
+
...generatedSchemas,
|
|
39
|
+
schema: generatedSchemas.schema.transform(val => val as SHA256),
|
|
40
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import * as PublicKeyHash from '@taqueria/protocol/PublicKeyHash';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
const internalSchema = z.object({
|
|
6
|
+
encryptedKey: z.string({ description: 'Sandbox Account Encrypted Key' }).min(1),
|
|
7
|
+
publicKeyHash: PublicKeyHash.schemas.schema.describe('Sandbox Account Public Key Hash'),
|
|
8
|
+
secretKey: z.string({ description: 'Sandbox Account Secret Key' }).min(1),
|
|
9
|
+
}, { description: 'Sandbox Account Configuration' });
|
|
10
|
+
|
|
11
|
+
export const rawSchema = z.object({
|
|
12
|
+
encryptedKey: z.string({ description: 'Sandbox Account Encrypted Key' }).min(1),
|
|
13
|
+
publicKeyHash: z.string({ description: 'Sandbox Account Public Key Hash' }).min(1),
|
|
14
|
+
secretKey: z.string({ description: 'Sandbox Account Secret Key' }).min(1),
|
|
15
|
+
}, { description: 'Sandbox Account Configuration' });
|
|
16
|
+
|
|
17
|
+
type Input = z.infer<typeof internalSchema>;
|
|
18
|
+
|
|
19
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
20
|
+
|
|
21
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
|
|
22
|
+
rawSchema,
|
|
23
|
+
internalSchema,
|
|
24
|
+
parseErrMsg: 'The sandbox account configuration is invalid',
|
|
25
|
+
unknownErrMsg: 'Something went wrong trying to parse the sandbox account configuration',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type SandboxAccountConfig = z.infer<typeof generatedSchemas.schema>;
|
|
29
|
+
export type t = SandboxAccountConfig;
|
|
30
|
+
export const { create, of, make } = factory;
|
|
31
|
+
|
|
32
|
+
export const schemas = {
|
|
33
|
+
...generatedSchemas,
|
|
34
|
+
schema: generatedSchemas.schema.transform(val => val as SandboxAccountConfig),
|
|
35
|
+
};
|
package/SandboxConfig.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import * as EconomicalProtocolHash from '@taqueria/protocol/EconomicalProtocolHash';
|
|
3
|
+
import * as HumanReadableIdentifier from '@taqueria/protocol/HumanReadableIdentifier';
|
|
4
|
+
import * as SandboxAccountConfig from '@taqueria/protocol/SandboxAccountConfig';
|
|
5
|
+
import * as Url from '@taqueria/protocol/Url';
|
|
6
|
+
import * as Verb from '@taqueria/protocol/Verb';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
9
|
+
const accountMapSchema = z.record(
|
|
10
|
+
z.union([
|
|
11
|
+
z.string().nonempty(),
|
|
12
|
+
SandboxAccountConfig.schemas.schema,
|
|
13
|
+
]),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const rawSchema = z.object({
|
|
17
|
+
label: z.string({ description: 'Sandbox Label' }).min(1),
|
|
18
|
+
rpcUrl: z.string({ description: 'Sandbox RPC Url' }).min(5).url(),
|
|
19
|
+
protocol: z.string({ description: 'Sandbox Protocol Hash' }).min(8),
|
|
20
|
+
attributes: z.record(
|
|
21
|
+
z.union(
|
|
22
|
+
[z.string(), z.number(), z.boolean()],
|
|
23
|
+
{ description: 'Sandbox Attribute' },
|
|
24
|
+
),
|
|
25
|
+
{ description: 'Sandbox Attributes' },
|
|
26
|
+
).optional(),
|
|
27
|
+
plugin: Verb.rawSchema.describe('Sandbox Plugin').optional(),
|
|
28
|
+
accounts: z.union([
|
|
29
|
+
z.object({ default: z.string().min(1) }),
|
|
30
|
+
z.record(SandboxAccountConfig.rawSchema),
|
|
31
|
+
], { description: 'Sandbox Accounts' }).optional(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const internalSchema = z.object({
|
|
35
|
+
label: HumanReadableIdentifier.schemas.schema.describe('Sandbox Label'),
|
|
36
|
+
rpcUrl: Url.schemas.schema.describe('Sandbox RPC Url'),
|
|
37
|
+
protocol: EconomicalProtocolHash.schemas.schema.describe('Sandbox Protocol Hash'),
|
|
38
|
+
attributes: z.record(
|
|
39
|
+
z.union([z.string(), z.number(), z.boolean()]),
|
|
40
|
+
{ description: 'Sandbox Attributes' },
|
|
41
|
+
).optional(),
|
|
42
|
+
plugin: Verb.schemas.schema.describe('Sandbox Plugin').optional(),
|
|
43
|
+
accounts: accountMapSchema.optional(),
|
|
44
|
+
}, { description: 'Sandbox Configuration' });
|
|
45
|
+
|
|
46
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
47
|
+
type Input = z.infer<typeof internalSchema>;
|
|
48
|
+
|
|
49
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
|
|
50
|
+
rawSchema,
|
|
51
|
+
internalSchema,
|
|
52
|
+
parseErrMsg: (value: unknown) => `${value} is not a valid sandbox configuration `,
|
|
53
|
+
unknownErrMsg: 'Something went wrong trying to parse the sandbox configuration',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export type SandboxConfig = z.infer<typeof generatedSchemas.schema>;
|
|
57
|
+
export type t = SandboxConfig;
|
|
58
|
+
export const { create, of, make } = factory;
|
|
59
|
+
|
|
60
|
+
export const schemas = {
|
|
61
|
+
...generatedSchemas,
|
|
62
|
+
schema: generatedSchemas.schema.transform(val => val as SandboxConfig),
|
|
63
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
export const rawSchema = z.string({ description: 'SanitizedAbsPath' }).min(1);
|
|
6
|
+
|
|
7
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
8
|
+
|
|
9
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
10
|
+
isStringLike: true,
|
|
11
|
+
rawSchema,
|
|
12
|
+
transformer: (value: unknown) => path.resolve(value as string) as unknown,
|
|
13
|
+
parseErrMsg: (value: unknown) => `${value} is an invalid absolute path`,
|
|
14
|
+
unknownErrMsg: (value: unknown) => `Something went wrong trying to parse the absolute path, ${value}`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export type SanitizedAbsPath = z.infer<typeof generatedSchemas.schema>;
|
|
18
|
+
export type t = SanitizedAbsPath;
|
|
19
|
+
export const { create, make, of } = factory;
|
|
20
|
+
export const schemas = {
|
|
21
|
+
...generatedSchemas,
|
|
22
|
+
schema: generatedSchemas.schema.transform(val => val as SanitizedAbsPath),
|
|
23
|
+
};
|
package/SanitizedArgs.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import * as SanitizedAbsPath from '@taqueria/protocol/SanitizedAbsPath';
|
|
3
|
+
import * as Url from '@taqueria/protocol/Url';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
export const rawSchema = z.object({
|
|
7
|
+
_: z.array(z.union([z.string().min(1), z.number()])),
|
|
8
|
+
projectDir: SanitizedAbsPath.schemas.schema,
|
|
9
|
+
maxConcurrency: z.preprocess(
|
|
10
|
+
val => typeof val === 'string' ? parseInt(val) : Number(val),
|
|
11
|
+
z.number().int().min(1).default(10),
|
|
12
|
+
),
|
|
13
|
+
debug: z.preprocess(
|
|
14
|
+
val => Boolean(val),
|
|
15
|
+
z.boolean().default(false),
|
|
16
|
+
),
|
|
17
|
+
disableState: z.preprocess(
|
|
18
|
+
val => Boolean(val),
|
|
19
|
+
z.boolean().default(false),
|
|
20
|
+
),
|
|
21
|
+
logPluginRequests: z.preprocess(
|
|
22
|
+
val => Boolean(val),
|
|
23
|
+
z.boolean().default(false),
|
|
24
|
+
),
|
|
25
|
+
fromVsCode: z.preprocess(
|
|
26
|
+
val => Boolean(val),
|
|
27
|
+
z.boolean().default(false),
|
|
28
|
+
),
|
|
29
|
+
version: z.preprocess(
|
|
30
|
+
val => Boolean(val),
|
|
31
|
+
z.boolean().optional(),
|
|
32
|
+
),
|
|
33
|
+
build: z.preprocess(
|
|
34
|
+
val => Boolean(val),
|
|
35
|
+
z.boolean().optional(),
|
|
36
|
+
),
|
|
37
|
+
help: z.preprocess(
|
|
38
|
+
val => Boolean(val),
|
|
39
|
+
z.boolean().optional(),
|
|
40
|
+
),
|
|
41
|
+
yes: z.preprocess(
|
|
42
|
+
val => Boolean(val),
|
|
43
|
+
z.boolean().optional(),
|
|
44
|
+
),
|
|
45
|
+
plugin: z.string().min(1).optional(),
|
|
46
|
+
env: z.union([z.literal('production'), z.literal('testing'), z.literal('development'), z.string().nonempty()])
|
|
47
|
+
.default('development'),
|
|
48
|
+
quickstart: z.string().min(1).optional(),
|
|
49
|
+
setBuild: z.preprocess(
|
|
50
|
+
val => String(val),
|
|
51
|
+
z.string().min(3),
|
|
52
|
+
),
|
|
53
|
+
setVersion: z.string().min(3),
|
|
54
|
+
template: z.string().min(1).optional(),
|
|
55
|
+
pluginName: z.string().min(1).optional(),
|
|
56
|
+
}, { description: 'Sanitizied Args' }).passthrough();
|
|
57
|
+
|
|
58
|
+
export const scaffoldRawSchema = rawSchema.extend({
|
|
59
|
+
scaffoldProjectDir: z.string().min(1).transform((val: unknown) => val as SanitizedAbsPath.t),
|
|
60
|
+
scaffoldUrl: z.string().min(1).url().transform((val: unknown) => val as Url.t),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const provisionRawSchema = rawSchema
|
|
64
|
+
.extend({
|
|
65
|
+
operation: z
|
|
66
|
+
.string()
|
|
67
|
+
.min(1)
|
|
68
|
+
.describe('Operation name'),
|
|
69
|
+
name: z
|
|
70
|
+
.string()
|
|
71
|
+
.min(1)
|
|
72
|
+
.regex(
|
|
73
|
+
/^[a-z0-9]+[a-z0-9-_]$/,
|
|
74
|
+
'Provisioner name must consist of one or more letters/numbers and may not start with an underscore or dash.',
|
|
75
|
+
)
|
|
76
|
+
.describe('Provisioner name')
|
|
77
|
+
.optional(),
|
|
78
|
+
})
|
|
79
|
+
.passthrough();
|
|
80
|
+
|
|
81
|
+
export const managePluginRawSchema = rawSchema.omit({ pluginName: true }).extend({
|
|
82
|
+
pluginName: z.string().min(1),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const versionRawSchema = rawSchema.extend({
|
|
86
|
+
version: z.boolean().default(true),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
90
|
+
type RawScaffoldInput = z.infer<typeof scaffoldRawSchema>;
|
|
91
|
+
type RawProvisionInput = z.infer<typeof provisionRawSchema>;
|
|
92
|
+
type RawManagePluginInput = z.infer<typeof managePluginRawSchema>;
|
|
93
|
+
type RawVersionInput = z.infer<typeof versionRawSchema>;
|
|
94
|
+
|
|
95
|
+
export const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
96
|
+
rawSchema,
|
|
97
|
+
parseErrMsg: 'The arguments provided are invalid',
|
|
98
|
+
unknownErrMsg: 'Something went wrong parsing the command-line arguments',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const { create, of, make } = factory;
|
|
102
|
+
|
|
103
|
+
export type SanitizedArgs = z.infer<typeof generatedSchemas.schema>;
|
|
104
|
+
export type t = SanitizedArgs;
|
|
105
|
+
|
|
106
|
+
export const schemas = {
|
|
107
|
+
...generatedSchemas,
|
|
108
|
+
schema: generatedSchemas.schema.transform(val => val as SanitizedArgs),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const scaffoldTaskArgs = createType<RawScaffoldInput, RawScaffoldInput>({
|
|
112
|
+
rawSchema: scaffoldRawSchema,
|
|
113
|
+
parseErrMsg: 'The arguments provided are invalid for the scaffold task',
|
|
114
|
+
unknownErrMsg: 'Something went wrong parsing the arguments for the scaffold task',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const provisionTaskArgs = createType<RawProvisionInput, RawProvisionInput>({
|
|
118
|
+
rawSchema: provisionRawSchema,
|
|
119
|
+
parseErrMsg: 'The arguments provided are invalid for the provision task',
|
|
120
|
+
unknownErrMsg: 'Something went wrong parsing the arguments for the provision task',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export const installTaskArgs = createType<RawManagePluginInput, RawManagePluginInput>({
|
|
124
|
+
rawSchema: managePluginRawSchema,
|
|
125
|
+
parseErrMsg: 'The arguments provided are invalid for the install task',
|
|
126
|
+
unknownErrMsg: 'Something went wrong parsing the arguments for the install task',
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const uninstallTaskArgs = createType<RawManagePluginInput, RawManagePluginInput>({
|
|
130
|
+
rawSchema: managePluginRawSchema,
|
|
131
|
+
parseErrMsg: 'The arguments provided are invalid for the uninstall task',
|
|
132
|
+
unknownErrMsg: 'Something went wrong parsing the arguments for the uninstall task',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export type ScaffoldTaskArgs = z.infer<typeof scaffoldTaskArgs.schemas.schema>;
|
|
136
|
+
export type ProvisionTaskArgs = z.infer<typeof provisionTaskArgs.schemas.schema>;
|
|
137
|
+
export type InstallTaskArgs = z.infer<typeof installTaskArgs.schemas.schema>;
|
|
138
|
+
export type UninstallTaskArgs = z.infer<typeof uninstallTaskArgs.schemas.schema>;
|
|
139
|
+
|
|
140
|
+
export const createScaffoldTaskArgs = scaffoldTaskArgs.factory.from;
|
|
141
|
+
export const makeScaffoldTaskArgs = scaffoldTaskArgs.factory.make;
|
|
142
|
+
export const ofScaffoldTaskArgs = scaffoldTaskArgs.factory.of;
|
|
143
|
+
|
|
144
|
+
export const createProvisionTaskArgs = provisionTaskArgs.factory.create;
|
|
145
|
+
export const makeProvisionTaskArgs = provisionTaskArgs.factory.make;
|
|
146
|
+
export const ofProvisionTaskArgs = provisionTaskArgs.factory.of;
|
|
147
|
+
|
|
148
|
+
export const createInstallTaskArgs = installTaskArgs.factory.create;
|
|
149
|
+
export const makeInstallTaskArgs = installTaskArgs.factory.make;
|
|
150
|
+
export const ofInstallTaskArgs = installTaskArgs.factory.of;
|
|
151
|
+
|
|
152
|
+
export const createUninstallTaskArgs = uninstallTaskArgs.factory.create;
|
|
153
|
+
export const makeUninstallTaskArgs = uninstallTaskArgs.factory.make;
|
|
154
|
+
export const ofUninstallTaskArgs = uninstallTaskArgs.factory.of;
|
package/SanitizedPath.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const rawSchema = z
|
|
5
|
+
.string({ description: 'Sanitized Path' })
|
|
6
|
+
.transform(value => {
|
|
7
|
+
const result = value.match(/^(\.\.|\.\/|\/)/);
|
|
8
|
+
return result ? value : `./${value}`;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
12
|
+
|
|
13
|
+
const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
|
|
14
|
+
isStringLike: true,
|
|
15
|
+
rawSchema,
|
|
16
|
+
parseErrMsg: (value: unknown) => `${value} is an invalid filesystem path`,
|
|
17
|
+
unknownErrMsg: (value: unknown) => `Something went wrong trying to parse the filesystem path, ${value}`,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type SanitizedPath = z.infer<typeof generatedSchemas.schema>;
|
|
21
|
+
export type t = SanitizedPath;
|
|
22
|
+
export const { create, of, make } = factory;
|
|
23
|
+
export const schemas = {
|
|
24
|
+
...generatedSchemas,
|
|
25
|
+
schema: generatedSchemas.schema.transform(val => val as SanitizedPath),
|
|
26
|
+
};
|
package/SingleChar.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import createType from '@taqueria/protocol/Base';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const rawSchema = z
|
|
5
|
+
.string({ description: 'Single character' })
|
|
6
|
+
.regex(/^[A-Za-z]$/, 'Must be a single character');
|
|
7
|
+
|
|
8
|
+
type RawInput = z.infer<typeof rawSchema>;
|
|
9
|
+
|
|
10
|
+
export const { factory, schemas: generatedSchemas } = createType<RawInput, RawInput>({
|
|
11
|
+
isStringLike: true,
|
|
12
|
+
rawSchema,
|
|
13
|
+
parseErrMsg: (value: unknown) => `${value} is not a single character`,
|
|
14
|
+
unknownErrMsg: `Something went wrong trying to parse a single character`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export type SingleChar = z.infer<typeof generatedSchemas.schema>;
|
|
18
|
+
export type t = SingleChar;
|
|
19
|
+
export const { create, of, make } = factory;
|
|
20
|
+
export const schemas = {
|
|
21
|
+
...generatedSchemas,
|
|
22
|
+
schema: generatedSchemas.schema.transform(val => val as SingleChar),
|
|
23
|
+
};
|
package/TaqError.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { map, reject } from 'fluture';
|
|
2
|
+
import { ZodError } from 'zod';
|
|
3
|
+
|
|
4
|
+
export type ErrorType =
|
|
5
|
+
| 'E_INVALID_PATH_DOES_NOT_EXIST'
|
|
6
|
+
| 'E_INVALID_PATH_ALREADY_EXISTS'
|
|
7
|
+
| 'E_INVALID_CONFIG'
|
|
8
|
+
| 'E_INVALID_JSON'
|
|
9
|
+
| 'E_FORK'
|
|
10
|
+
| 'E_INVALID_TASK'
|
|
11
|
+
| 'E_READFILE'
|
|
12
|
+
| 'E_NPM_INIT'
|
|
13
|
+
| 'E_INVALID_PLUGIN_RESPONSE'
|
|
14
|
+
| 'E_INVALID_ARGS'
|
|
15
|
+
| 'E_MKDIR_FAILED'
|
|
16
|
+
| 'E_GIT_CLONE_FAILED'
|
|
17
|
+
| 'E_PROVISION'
|
|
18
|
+
| 'E_PARSE'
|
|
19
|
+
| 'E_PARSE_UNKNOWN'
|
|
20
|
+
| 'E_INVALID_ARCH'
|
|
21
|
+
| 'E_NO_PROVISIONS';
|
|
22
|
+
|
|
23
|
+
export interface TaqError {
|
|
24
|
+
readonly kind: ErrorType;
|
|
25
|
+
msg: string;
|
|
26
|
+
previous?: TaqError | Error | unknown;
|
|
27
|
+
context?: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type t = TaqError;
|
|
31
|
+
|
|
32
|
+
export class E_TaqError extends Error {
|
|
33
|
+
readonly context;
|
|
34
|
+
readonly kind;
|
|
35
|
+
readonly previous;
|
|
36
|
+
constructor(taqErr: TaqError) {
|
|
37
|
+
super(taqErr.msg);
|
|
38
|
+
this.context = taqErr.context;
|
|
39
|
+
this.kind = taqErr.kind;
|
|
40
|
+
this.name = this.kind;
|
|
41
|
+
this.previous = taqErr.previous;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const toFutureParseErr = <T>(previous: ZodError, msg: string, context?: unknown) =>
|
|
46
|
+
reject(toParseErr(previous, msg, context))
|
|
47
|
+
.pipe(map((val: unknown) => val as T));
|
|
48
|
+
|
|
49
|
+
export const toParseErr = (previous: ZodError, msg: string, context?: unknown) =>
|
|
50
|
+
create({
|
|
51
|
+
kind: 'E_PARSE',
|
|
52
|
+
msg: msg,
|
|
53
|
+
context,
|
|
54
|
+
previous,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const toParseUnknownErr = (previous: Error | TaqError | E_TaqError | unknown, msg: string, context?: unknown) =>
|
|
58
|
+
create({
|
|
59
|
+
kind: 'E_PARSE_UNKNOWN',
|
|
60
|
+
msg: msg,
|
|
61
|
+
context,
|
|
62
|
+
previous,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const toFutureParseUnknownErr = <T>(
|
|
66
|
+
previous: Error | TaqError | E_TaqError | unknown,
|
|
67
|
+
msg: string,
|
|
68
|
+
context?: unknown,
|
|
69
|
+
) =>
|
|
70
|
+
reject(toParseUnknownErr(previous, msg, context))
|
|
71
|
+
.pipe(map((val: unknown) => val as T));
|
|
72
|
+
|
|
73
|
+
export const create = (err: TaqError) => err;
|