Skip to content

Commit

Permalink
Introduce the notion of ExpandedSeed{Packet,Data} and non-expanded.
Browse files Browse the repository at this point in the history
Currently they're the same exact types, just aliases.

The idea is that the non-expanded are the raw packet, and might include nested seeds.

Part of #2.
  • Loading branch information
jkomoros committed Jun 24, 2023
1 parent 9c0f8a0 commit 3b0e423
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/garden.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
SeedData,
ExpandedSeedData,
SeedPacket,
EnvironmentData,
SeedReference,
Expand Down Expand Up @@ -104,7 +104,7 @@ export class Garden {
return;
}

plantSeed(ref : AbsoluteSeedReference, data : SeedData) {
plantSeed(ref : AbsoluteSeedReference, data : ExpandedSeedData) {
if (this._seeds[ref.packet] == undefined) {
this._seeds[ref.packet] = {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
AbsoluteSeedReference,
SeedID,
SeedData,
ExpandedSeedData,
SeedDataType,
SeedPacketAbsoluteLocation,
Value
Expand All @@ -16,7 +16,7 @@ import {
grow
} from './grow.js';

export class Seed<D extends SeedData = SeedData> {
export class Seed<D extends ExpandedSeedData = ExpandedSeedData> {

_garden : Garden;
_ref : AbsoluteSeedReference;
Expand Down
16 changes: 10 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,23 @@ export type SeedDataIf = z.infer<typeof seedDataIf>;
*
*/

export const seedData = z.discriminatedUnion('type', [
export const expandedSeedData = z.discriminatedUnion('type', [
seedDataPrompt,
seedDataLog,
seedDataIf
]);

export type SeedData = z.infer<typeof seedData>;
export type ExpandedSeedData = z.infer<typeof expandedSeedData>;

export type SeedDataType = SeedData['type'];
export type SeedDataType = ExpandedSeedData['type'];

export const seedPacket = z.object({
export const expandedSeedPacket = z.object({
version: z.literal(0),
seeds: z.record(seedID, seedData)
seeds: z.record(seedID, expandedSeedData)
});

export type SeedPacket = z.infer<typeof seedPacket>;
export type ExpandedSeedPacket = z.infer<typeof expandedSeedPacket>;

//TODO: allow nesting of this type.
export const seedPacket = expandedSeedPacket;
export type SeedPacket = ExpandedSeedPacket;

0 comments on commit 3b0e423

Please sign in to comment.