@taqueria/protocol 0.3.1 → 0.4.0-rc1

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.
@@ -0,0 +1,28 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import { z } from 'zod';
3
+
4
+ export const rawSchema = z.object({
5
+ name: z.string({ description: 'Plugin Name' }).min(1),
6
+ type: z.union(
7
+ [z.literal('npm'), z.literal('binary'), z.literal('deno')],
8
+ { description: 'Plugin Type' },
9
+ ),
10
+ }).describe('InstalledPlugin');
11
+
12
+ type RawInput = z.infer<typeof rawSchema>;
13
+
14
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
15
+ rawSchema,
16
+ parseErrMsg: (value: unknown) => `${value} is not a valid installed plugin`,
17
+ unknownErrMsg: 'Something went wrong when parsing the installed plugin',
18
+ });
19
+
20
+ export type InstalledPlugin = z.infer<typeof generatedSchemas.schema>;
21
+ export type t = InstalledPlugin;
22
+
23
+ export const { create, of, make } = factory;
24
+
25
+ export const schemas = {
26
+ ...generatedSchemas,
27
+ schema: generatedSchemas.schema.transform(val => val as InstalledPlugin),
28
+ };
@@ -0,0 +1,45 @@
1
+ import createType, { Flatten } from '@taqueria/protocol/Base';
2
+ import * as Config from '@taqueria/protocol/Config';
3
+ import * as SanitizedAbsPath from '@taqueria/protocol/SanitizedAbsPath';
4
+ import * as SHA256 from '@taqueria/protocol/SHA256';
5
+ import { z } from 'zod';
6
+
7
+ export const rawSchema = Config.rawSchema
8
+ .omit({ plugins: true })
9
+ .extend({
10
+ plugins: Config.pluginsRawSchema,
11
+ projectDir: SanitizedAbsPath.rawSchema.describe('loadedConfig.projectDir'),
12
+ configFile: SanitizedAbsPath.rawSchema.describe('loadedConfig.configFile'),
13
+ hash: SHA256.rawSchema.describe('loadedConfig.hash'),
14
+ })
15
+ .describe('LoadedConfig');
16
+
17
+ export const internalSchema = Config.internalSchema
18
+ .omit({ plugins: true })
19
+ .extend({
20
+ plugins: Config.pluginsInternalSchema,
21
+ projectDir: SanitizedAbsPath.schemas.schema.describe('loadedConfig.projectDir'),
22
+ configFile: SanitizedAbsPath.schemas.schema.describe('loadedConfig.configFile'),
23
+ hash: SHA256.schemas.schema.describe('loadedConfig.hash'),
24
+ })
25
+ .describe('LoadedConfig');
26
+
27
+ type RawInput = z.infer<typeof rawSchema>;
28
+ type Input = Flatten<z.infer<typeof internalSchema>>;
29
+
30
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
31
+ rawSchema,
32
+ internalSchema,
33
+ parseErrMsg: (value: unknown) => `The following configuration is invalid: ${value}`,
34
+ unknownErrMsg: 'Something went wrong trying to parse the configuration to load',
35
+ });
36
+
37
+ export type LoadedConfig = z.infer<typeof generatedSchemas.schema>;
38
+ export type t = LoadedConfig;
39
+ export const { create, of, make } = factory;
40
+ export const schemas = {
41
+ ...generatedSchemas,
42
+ schema: generatedSchemas.schema.transform(val => val as LoadedConfig),
43
+ };
44
+
45
+ export const toConfig = (config: LoadedConfig) => Config.make(config);
@@ -0,0 +1,39 @@
1
+ import createType, { Flatten } from '@taqueria/protocol/Base';
2
+ import * as EconomicalProtocolHash from '@taqueria/protocol/EconomicalProtocolHash';
3
+ import * as Faucet from '@taqueria/protocol/Faucet';
4
+ import * as HumanReadableIdentifier from '@taqueria/protocol/HumanReadableIdentifier';
5
+ import * as Url from '@taqueria/protocol/Url';
6
+ import { z } from 'zod';
7
+
8
+ export const rawSchema = z.object({
9
+ label: HumanReadableIdentifier.rawSchema,
10
+ rpcUrl: Url.rawSchema,
11
+ protocol: EconomicalProtocolHash.rawSchema,
12
+ faucet: Faucet.rawSchema.describe('Network Faucet'),
13
+ }).describe('Network Config');
14
+
15
+ const internalSchema = z.object({
16
+ label: HumanReadableIdentifier.schemas.schema.describe('Network Label'),
17
+ rpcUrl: Url.schemas.schema.describe('Network RPC Url'),
18
+ protocol: EconomicalProtocolHash.schemas.schema.describe('Network Protocol Hash'),
19
+ faucet: Faucet.schemas.schema.describe('Network Faucet'),
20
+ }).describe('Network Config');
21
+
22
+ type RawInput = z.infer<typeof rawSchema>;
23
+ type Input = z.infer<typeof internalSchema>;
24
+
25
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
26
+ rawSchema,
27
+ internalSchema,
28
+ parseErrMsg: (value: unknown) => `${value} is not a valid network configuration`,
29
+ unknownErrMsg: 'Something went wrong trying to parse the network configuration',
30
+ });
31
+
32
+ export type NetworkConfig = Flatten<z.infer<typeof generatedSchemas.schema>>;
33
+ export type t = NetworkConfig;
34
+ export const { create, of, make } = factory;
35
+
36
+ export const schemas = {
37
+ ...generatedSchemas,
38
+ schema: generatedSchemas.schema.transform(val => val as NetworkConfig),
39
+ };
package/Operation.ts ADDED
@@ -0,0 +1,70 @@
1
+ import createType, { Flatten } from '@taqueria/protocol/Base';
2
+ import * as Command from '@taqueria/protocol/Command';
3
+ import * as Option from '@taqueria/protocol/Option';
4
+ import * as PersistentState from '@taqueria/protocol/PersistentState';
5
+ import * as PositionalArg from '@taqueria/protocol/PositionalArg';
6
+ import * as RequestArgs from '@taqueria/protocol/RequestArgs';
7
+ import * as Verb from '@taqueria/protocol/Verb';
8
+ import { z } from 'zod';
9
+
10
+ type Handler = (state: PersistentState.t) => <T extends RequestArgs.t>(opts: T) => unknown;
11
+
12
+ export const rawSchema = z.object({
13
+ operation: Verb.rawSchema.describe('Operation Name'),
14
+ command: Command.rawSchema.describe('Operation Command'),
15
+ description: z.string({ description: 'Operation Description' }).optional(),
16
+ positionals: z.array(PositionalArg.rawSchema).default([]).describe('Operation Positional Args').optional(),
17
+ options: z.preprocess(
18
+ (val: unknown) => val ?? [],
19
+ z.array(
20
+ Option.rawSchema.describe('Operation Option'),
21
+ { description: 'Operation Options' },
22
+ ).optional(),
23
+ ),
24
+ handler: z.function()
25
+ .args(PersistentState.rawSchema)
26
+ .returns(
27
+ z.function()
28
+ .args(RequestArgs.schemas.internalSchema),
29
+ )
30
+ .describe('Operation Handler')
31
+ .transform((val: unknown) => val as Handler),
32
+ }).describe('Operation');
33
+
34
+ export const internalSchema = z.object({
35
+ operation: Verb.schemas.schema.describe('Operation Name'),
36
+ command: Command.schemas.schema.describe('Operation Command'),
37
+ description: z.string({ description: 'Optionation Description' }).optional(),
38
+ positionals: z.array(PositionalArg.schemas.schema).default([]).describe('Operation Positional Args').optional(),
39
+ options: z.preprocess(
40
+ (val: unknown) => val ?? [] as Option.t[],
41
+ z.array(Option.schemas.schema.describe('Operation Option'), { description: 'Operation Options' }).optional(),
42
+ ),
43
+ handler: z.function()
44
+ .args(PersistentState.rawSchema)
45
+ .returns(
46
+ z.function()
47
+ .args(RequestArgs.schemas.schema),
48
+ )
49
+ .describe('Operation Handler')
50
+ .transform((val: unknown) => val as Handler),
51
+ }).describe('Operation');
52
+
53
+ type Input = Flatten<z.infer<typeof internalSchema>>;
54
+ type RawInput = z.infer<typeof rawSchema>;
55
+
56
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
57
+ rawSchema,
58
+ internalSchema,
59
+ parseErrMsg: (value: unknown) => `The following operation is invalid: ${value}`,
60
+ unknownErrMsg: 'Something went wrong trying to parse the operation',
61
+ });
62
+
63
+ export type Operation = Flatten<z.infer<typeof generatedSchemas.schema>>;
64
+ export type t = Operation;
65
+ export const { make, of, create } = factory;
66
+
67
+ export const schemas = {
68
+ ...generatedSchemas,
69
+ schema: generatedSchemas.schema.transform(val => val as Operation),
70
+ };
package/Option.ts ADDED
@@ -0,0 +1,56 @@
1
+ import createType, { Flatten } 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
+
6
+ export const internalSchema = z.object({
7
+ shortFlag: SingleChar.schemas.schema.describe('Option Short Flag').optional(),
8
+ flag: Verb.schemas.schema.describe('Option Long Flag'),
9
+ description: z.string({ description: 'Option Description' }).min(1),
10
+ defaultValue: z.union(
11
+ [z.string(), z.number(), z.boolean()],
12
+ { description: 'Option Default Value' },
13
+ ).optional(),
14
+ choices: z.array(
15
+ z.string({ description: 'Option Choice' }),
16
+ { description: 'Option Choices' },
17
+ ).optional(),
18
+ required: z.boolean({ description: 'Option Is Required' }).default(false).optional(),
19
+ boolean: z.boolean({ description: 'Option Is Boolean' }).default(false).optional(),
20
+ }).describe('Option');
21
+
22
+ export const rawSchema = z.object({
23
+ shortFlag: SingleChar.rawSchema.describe('Option Short Flag').optional(),
24
+ flag: Verb.rawSchema.describe('Option Long Flag'),
25
+ description: z.string({ description: 'Option Description' }).min(1),
26
+ defaultValue: z.union(
27
+ [z.string(), z.number(), z.boolean()],
28
+ { description: 'Option Default Value' },
29
+ ).optional(),
30
+ choices: z.array(
31
+ z.string({ description: 'Option Choice' }),
32
+ { description: 'Option Choices' },
33
+ ).optional(),
34
+ required: z.boolean({ description: 'Option Is Required' }).default(false).optional(),
35
+ boolean: z.boolean({ description: 'Option Is Boolean' }).default(false).optional(),
36
+ }).describe('Option');
37
+
38
+ type RawInput = z.infer<typeof rawSchema>;
39
+ type Input = z.infer<typeof internalSchema>;
40
+
41
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
42
+ rawSchema,
43
+ internalSchema,
44
+ parseErrMsg: (value: unknown) => `The following option is invalid: ${value}`,
45
+ unknownErrMsg: 'Something went wrong trying to parse the option',
46
+ });
47
+
48
+ export type Option = Flatten<z.infer<typeof generatedSchemas.schema>>;
49
+ export type t = Option;
50
+
51
+ export const { make, create, of } = factory;
52
+
53
+ export const schemas = {
54
+ ...generatedSchemas,
55
+ schema: generatedSchemas.schema.transform(val => val as Option),
56
+ };
@@ -0,0 +1,33 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import * as Operation from '@taqueria/protocol/Operation';
3
+ import { z } from 'zod';
4
+
5
+ const internalSchema = Operation
6
+ .internalSchema
7
+ .describe('ParsedOperation')
8
+ .omit({ handler: true });
9
+
10
+ export const rawSchema = Operation
11
+ .rawSchema
12
+ .omit({ handler: true })
13
+ .describe('ParsedOperation');
14
+
15
+ type RawInput = z.infer<typeof rawSchema>;
16
+ type Input = z.infer<typeof internalSchema>;
17
+
18
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
19
+ rawSchema,
20
+ internalSchema,
21
+ parseErrMsg: (value: unknown) => `Could not parse the following operation: ${value}`,
22
+ unknownErrMsg: 'Something went wrong trying to parse an operation',
23
+ });
24
+
25
+ export type ParsedOperation = z.infer<typeof generatedSchemas.schema>;
26
+ export type t = ParsedOperation;
27
+
28
+ export const { create, make, of } = factory;
29
+
30
+ export const schemas = {
31
+ ...generatedSchemas,
32
+ schema: generatedSchemas.schema.transform(val => val as ParsedOperation),
33
+ };
@@ -0,0 +1,47 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import * as ParsedOperation from '@taqueria/protocol/ParsedOperation';
3
+ import * as PluginInfo from '@taqueria/protocol/PluginInfo';
4
+ import { z } from 'zod';
5
+
6
+ const internalSchema = PluginInfo.internalSchema.extend({
7
+ operations: z.preprocess(
8
+ val => val ?? [],
9
+ z.array(
10
+ ParsedOperation.schemas.schema,
11
+ { description: 'ParsedOperations' },
12
+ )
13
+ .optional(),
14
+ ),
15
+ }).describe('ParsedPluginInfo');
16
+
17
+ export const rawSchema = PluginInfo.internalSchema.extend({
18
+ operations: z.preprocess(
19
+ val => val ?? [],
20
+ z.array(
21
+ ParsedOperation.rawSchema,
22
+ { description: 'ParsedOperation' },
23
+ ),
24
+ )
25
+ .optional(),
26
+ }).describe('ParsedPluginInfo');
27
+
28
+ type Input = z.infer<typeof internalSchema>;
29
+
30
+ type RawInput = z.infer<typeof rawSchema>;
31
+
32
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
33
+ rawSchema,
34
+ internalSchema,
35
+ parseErrMsg: (value: unknown) =>
36
+ `The following plugin info gave us trouble when parsing the following plugin information: ${value}`,
37
+ unknownErrMsg: 'Something went wrong trying to parse the plugin information',
38
+ });
39
+
40
+ export type ParsedPluginInfo = z.infer<typeof generatedSchemas.schema>;
41
+ export type t = ParsedPluginInfo;
42
+ export const { create, of, make } = factory;
43
+
44
+ export const schemas = {
45
+ ...generatedSchemas,
46
+ schema: generatedSchemas.schema.transform(val => val as ParsedPluginInfo),
47
+ };
@@ -0,0 +1,67 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import * as SHA256 from '@taqueria/protocol/SHA256';
3
+ import * as Timestamp from '@taqueria/protocol/Timestamp';
4
+ import * as Verb from '@taqueria/protocol/Verb';
5
+ import { z } from 'zod';
6
+
7
+ const rawOpSchema = z.object({
8
+ hash: SHA256.rawSchema.describe('state.op.hash'),
9
+ time: Timestamp.rawSchema.describe('state.op.time'),
10
+ output: z.unknown().describe('state.op.output'),
11
+ }).describe('Persistent State Operation');
12
+
13
+ const rawTaskSchema = z.object({
14
+ time: Timestamp.rawSchema.describe('state.task.time'),
15
+ output: z.unknown().describe('state.task.output'),
16
+ });
17
+
18
+ const internalOpSchema = z.object({
19
+ hash: SHA256.schemas.schema.describe('state.op.hash'),
20
+ time: Timestamp.schemas.schema.describe('state.op.time'),
21
+ output: z.unknown().describe('state.op.output'),
22
+ });
23
+
24
+ const internalTaskSchema = z.object({
25
+ task: Verb.schemas.schema,
26
+ plugin: z.string().min(1),
27
+ time: Timestamp.schemas.schema.describe('state.task.time'),
28
+ output: z.unknown().describe('state.op.output'),
29
+ });
30
+
31
+ export type PersistedTask = z.infer<typeof internalTaskSchema>;
32
+
33
+ export type PersistedOperation = z.infer<typeof internalOpSchema>;
34
+
35
+ export const rawSchema = z.object({
36
+ operations: z.record(rawOpSchema),
37
+ tasks: z.record(rawTaskSchema),
38
+ });
39
+
40
+ export const internalSchema = z.object({
41
+ operations: z.record(internalOpSchema),
42
+ tasks: z.record(internalTaskSchema),
43
+ }).transform(val => ({
44
+ operations: val.operations as unknown as Record<string, PersistedOperation>,
45
+ tasks: val.tasks as unknown as Record<string, PersistedTask>,
46
+ }));
47
+
48
+ type RawInput = z.infer<typeof rawSchema>;
49
+
50
+ type Input = z.infer<typeof internalSchema>;
51
+
52
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
53
+ rawSchema,
54
+ parseErrMsg: `The persistent state is invalid`,
55
+ unknownErrMsg: `Something went wrong trying to parse the persistent state`,
56
+ });
57
+
58
+ export type PersistentState = z.infer<typeof generatedSchemas.schema>;
59
+ export type t = PersistentState;
60
+ export type State = PersistentState;
61
+
62
+ export const { create, of, make } = factory;
63
+
64
+ export const schemas = {
65
+ ...generatedSchemas,
66
+ schema: generatedSchemas.schema.transform(val => val as unknown as PersistentState),
67
+ };
package/PluginInfo.ts ADDED
@@ -0,0 +1,67 @@
1
+ import * as Alias from '@taqueria/protocol/Alias';
2
+ import createType, { Flatten } from '@taqueria/protocol/Base';
3
+ import * as Operation from '@taqueria/protocol/Operation';
4
+ import * as Task from '@taqueria/protocol/Task';
5
+ import * as VersionNumber from '@taqueria/protocol/VersionNumber';
6
+ import { z } from 'zod';
7
+
8
+ export const internalSchema = z.object({
9
+ name: z.string({ description: 'Plugin Name' }).min(1),
10
+ version: VersionNumber.schemas.schema.describe('Plugin Version #'),
11
+ schema: VersionNumber.schemas.schema.describe('Plugin Schema Version #'),
12
+ alias: Alias.schemas.schema.describe('Plugin Alias'),
13
+ tasks: z.preprocess(
14
+ val => val ?? [],
15
+ z.array(
16
+ Task.schemas.schema.describe('Plugin Task'),
17
+ { description: 'Plugin Tasks' },
18
+ ).optional(),
19
+ ),
20
+ operations: z.preprocess(
21
+ val => val ?? [],
22
+ z.array(
23
+ Operation.schemas.schema.describe('Plugin Operation'),
24
+ { description: 'Plugin Operations' },
25
+ ).optional(),
26
+ ),
27
+ }).describe('Plugin Schema');
28
+
29
+ export const rawSchema = z.object({
30
+ name: z.string({ description: 'Plugin Name' }).min(1),
31
+ version: VersionNumber.rawSchema.describe('Plugin Version #'),
32
+ schema: VersionNumber.rawSchema.describe('Plugin Schema Version #'),
33
+ alias: Alias.rawSchema.describe('Plugin Alias'),
34
+ tasks: z.preprocess(
35
+ val => val ?? [],
36
+ z.array(
37
+ Task.rawSchema.describe('Plugin Task'),
38
+ { description: 'Plugin Tasks' },
39
+ ).optional(),
40
+ ),
41
+ operations: z.preprocess(
42
+ val => val ?? [],
43
+ z.array(
44
+ Operation.rawSchema.describe('Plugin Operation'),
45
+ { description: 'Plugin Operations' },
46
+ ).optional(),
47
+ ),
48
+ }).describe('Plugin Schema');
49
+
50
+ type RawInput = z.infer<typeof rawSchema>;
51
+ type Input = Flatten<z.infer<typeof internalSchema>>;
52
+
53
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
54
+ rawSchema,
55
+ internalSchema,
56
+ parseErrMsg: 'The schema returned from the plugin is invalid',
57
+ unknownErrMsg: 'Something went wrong parsing the schema from a plugin',
58
+ });
59
+
60
+ export type PluginInfo = Flatten<z.infer<typeof generatedSchemas.schema>>;
61
+ export type t = PluginInfo;
62
+ export const { create, of, make } = factory;
63
+
64
+ export const schemas = {
65
+ ...generatedSchemas,
66
+ schema: generatedSchemas.schema.transform(val => val as unknown as PluginInfo),
67
+ };
@@ -0,0 +1,49 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import * as HumanReadableIdentifier from '@taqueria/protocol/HumanReadableIdentifier';
3
+ import { z } from 'zod';
4
+
5
+ export const rawSchema = z.object({
6
+ placeholder: HumanReadableIdentifier.rawSchema.describe('Positional Arg Placeholder'),
7
+ description: z.string({ description: 'Positional Arg Description' }).min(1),
8
+ defaultValue: z.union(
9
+ [z.string(), z.number(), z.boolean()],
10
+ { description: 'Positional Arg Default Value' },
11
+ ).optional(),
12
+ type: z.union(
13
+ [z.literal('string'), z.literal('number'), z.literal('boolean')],
14
+ { description: 'Positional Arg Datatype' },
15
+ ).optional(),
16
+ }).describe('Positional Arg');
17
+
18
+ const internalSchema = z.object({
19
+ placeholder: HumanReadableIdentifier.schemas.schema.describe('Positional Arg Placeholder'),
20
+ description: z.string({ description: 'Positional Arg Description' }).min(1),
21
+ defaultValue: z.union(
22
+ [z.string(), z.number(), z.boolean()],
23
+ { description: 'Positional Arg Default Value' },
24
+ ).optional(),
25
+ type: z.union(
26
+ [z.literal('string'), z.literal('number'), z.literal('boolean')],
27
+ { description: 'Positional Arg Datatype' },
28
+ ).optional(),
29
+ }).describe('Positional Arg');
30
+
31
+ type RawInput = z.infer<typeof rawSchema>;
32
+ type Input = z.infer<typeof internalSchema>;
33
+
34
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
35
+ rawSchema,
36
+ internalSchema,
37
+ parseErrMsg: (value: unknown) => `The following positional argument is invalid: ${value}`,
38
+ unknownErrMsg: 'Something went wrong parsing the positional argument',
39
+ });
40
+
41
+ export type PositionalArg = z.infer<typeof generatedSchemas.schema>;
42
+ export type t = PositionalArg;
43
+
44
+ export const { create, of, make } = factory;
45
+
46
+ export const schemas = {
47
+ ...generatedSchemas,
48
+ schema: generatedSchemas.schema.transform(val => val as unknown as PositionalArg),
49
+ };
package/Provisioner.ts ADDED
@@ -0,0 +1,61 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import * as ProvisionerID from '@taqueria/protocol/ProvisionerID';
3
+ import { z } from 'zod';
4
+
5
+ export const rawSchema = z.object(
6
+ {
7
+ id: ProvisionerID.rawSchema,
8
+ plugin: z
9
+ .string()
10
+ .min(1)
11
+ .describe('Provisioner Plugin')
12
+ .optional(),
13
+ operation: z
14
+ .union([
15
+ z.string().min(1),
16
+ z.literal('custom'),
17
+ ])
18
+ .describe('Provisioner Operation'),
19
+ command: z
20
+ .string()
21
+ .describe('Provisioner Custom Command')
22
+ .optional(),
23
+ label: z
24
+ .string()
25
+ .describe('Provisioner Label')
26
+ .optional(),
27
+ depends_on: z
28
+ .array(
29
+ ProvisionerID.rawSchema,
30
+ )
31
+ .optional(),
32
+ },
33
+ {
34
+ description: 'Provisioner',
35
+ },
36
+ )
37
+ .passthrough();
38
+
39
+ export const internalSchema = rawSchema.extend({
40
+ id: ProvisionerID.schemas.schema,
41
+ depends_on: z.array(ProvisionerID.schemas.schema).optional(),
42
+ });
43
+
44
+ type RawInput = z.infer<typeof rawSchema>;
45
+ type Input = z.infer<typeof internalSchema>;
46
+
47
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
48
+ rawSchema,
49
+ internalSchema,
50
+ parseErrMsg: 'There was a problem trying to parse the provisioner',
51
+ unknownErrMsg: 'Something went wrong trying to parse the provisioner',
52
+ });
53
+
54
+ export type Provisioner = z.infer<typeof generatedSchemas.schema>;
55
+ export type t = Provisioner;
56
+ export const { create, of, make } = factory;
57
+
58
+ export const schemas = {
59
+ ...generatedSchemas,
60
+ schema: generatedSchemas.schema.transform(val => val as unknown as Provisioner),
61
+ };
@@ -0,0 +1,25 @@
1
+ import createType from '@taqueria/protocol/Base';
2
+ import { z } from 'zod';
3
+
4
+ export const rawSchema = z
5
+ .string()
6
+ .min(1)
7
+ .regex(/^[A-Za-z0-9]+[A-Za-z0-9-_]+\.[A-Za-z0-9]+[A-Za-z0-9-_]+\.[A-Za-z0-9]+[A-Za-z0-9-_]+$/)
8
+ .describe('Provisioner ID');
9
+
10
+ type RawInput = z.infer<typeof rawSchema>;
11
+
12
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, RawInput>({
13
+ rawSchema,
14
+ parseErrMsg: (value: unknown) => `${value} is not a valid provisioner ID`,
15
+ unknownErrMsg: 'Something went wrong trying to parse the provision ID',
16
+ });
17
+
18
+ export type ProvisionerID = z.infer<typeof generatedSchemas.schema>;
19
+ export type t = ProvisionerID;
20
+ export const { create, of, make } = factory;
21
+
22
+ export const schemas = {
23
+ ...generatedSchemas,
24
+ schema: generatedSchemas.schema.transform(val => val as ProvisionerID),
25
+ };
package/Provisions.ts ADDED
@@ -0,0 +1,70 @@
1
+ import createType, { Flatten } from '@taqueria/protocol/Base';
2
+ import * as Provisioner from '@taqueria/protocol/Provisioner';
3
+ import * as ProvisionerID from '@taqueria/protocol/ProvisionerID';
4
+ import { memoizy } from 'memoizy';
5
+ import { partitionArray, uniq } from 'rambda';
6
+ import { z } from 'zod';
7
+
8
+ const getInvalidIds = memoizy((provisions: Provisioner.t[]) => {
9
+ const ids = provisions.map(p => p.id);
10
+ return provisions.reduce(
11
+ (retval, provision) => {
12
+ const depends_on = provision.depends_on ?? [];
13
+ const invalid = partitionArray(
14
+ (id: ProvisionerID.t) => ids.includes(id),
15
+ depends_on,
16
+ ).pop() as ProvisionerID.t[];
17
+
18
+ return uniq([...retval, ...invalid]);
19
+ },
20
+ [] as ProvisionerID.t[],
21
+ );
22
+ });
23
+
24
+ const rawSchema = z
25
+ .array(
26
+ Provisioner.rawSchema,
27
+ )
28
+ .refine(
29
+ provisions => getInvalidIds(provisions).length === 0,
30
+ provisions => ({
31
+ message:
32
+ `One or more of your provisioners depends on an invalid provisioner. The following provisioner ids were referenced that do not exist: ${
33
+ getInvalidIds(provisions).join(', ')
34
+ }`,
35
+ }),
36
+ )
37
+ .describe('Provisions');
38
+
39
+ type RawInput = z.infer<typeof rawSchema>;
40
+
41
+ const internalSchema = z
42
+ .array(Provisioner.schemas.schema)
43
+ .refine(
44
+ provisions => getInvalidIds(provisions).length === 0,
45
+ provisions => ({
46
+ message:
47
+ `One or more of your provisioners depends on an invalid provisioner. The following provisioner ids were referenced that do not exist: ${
48
+ getInvalidIds(provisions).join(', ')
49
+ }`,
50
+ }),
51
+ )
52
+ .describe('Provisions');
53
+
54
+ type Input = z.infer<typeof internalSchema>;
55
+
56
+ export const { schemas: generatedSchemas, factory } = createType<RawInput, Input>({
57
+ rawSchema,
58
+ internalSchema,
59
+ parseErrMsg: (value: unknown) => `The following provision is invalid: ${value}`,
60
+ unknownErrMsg: 'Something went wrong parsing the list of provisioners',
61
+ });
62
+
63
+ export type Provisions = Flatten<z.infer<typeof generatedSchemas.schema>>;
64
+ export type t = Provisions;
65
+ export const { create, of, make } = factory;
66
+
67
+ export const schemas = {
68
+ ...generatedSchemas,
69
+ schema: generatedSchemas.schema.transform(val => val as Provisions),
70
+ };