Skip to content

Commit

Permalink
undo default change
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed May 17, 2024
1 parent 7a1b7c0 commit 0937cd6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 122 deletions.
1 change: 1 addition & 0 deletions packages/store/ts/config/v2/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const CODEGEN_DEFAULTS = {
export type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;

export const TABLE_CODEGEN_DEFAULTS = {
outputDirectory: "tables",
tableIdArgument: false,
storeArgument: false,
} as const;
Expand Down
48 changes: 8 additions & 40 deletions packages/store/ts/config/v2/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ describe("defineStore", () => {
key: ["age"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -93,11 +89,7 @@ describe("defineStore", () => {
key: ["age"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -147,11 +139,7 @@ describe("defineStore", () => {
key: ["age", "id"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -202,11 +190,7 @@ describe("defineStore", () => {
key: ["firstKey", "firstAge"],
name: "First",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand All @@ -229,11 +213,7 @@ describe("defineStore", () => {
key: ["secondKey", "secondAge"],
name: "Second",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -288,11 +268,7 @@ describe("defineStore", () => {
key: ["firstKey", "firstAge"],
name: "First",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand All @@ -315,11 +291,7 @@ describe("defineStore", () => {
key: ["secondKey", "secondAge"],
name: "Second",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -430,11 +402,7 @@ describe("defineStore", () => {
key: ["name"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down
24 changes: 4 additions & 20 deletions packages/store/ts/config/v2/storeWithShorthands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ describe("defineStoreWithShorthands", () => {
key: ["id"],
name: "Name",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -68,11 +64,7 @@ describe("defineStoreWithShorthands", () => {
key: ["id"],
name: "Name",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -114,11 +106,7 @@ describe("defineStoreWithShorthands", () => {
key: ["id"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -160,11 +148,7 @@ describe("defineStoreWithShorthands", () => {
key: ["id"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down
6 changes: 3 additions & 3 deletions packages/store/ts/config/v2/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("resolveTable", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,

dataStruct: true as boolean,
},
type: "table",
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("resolveTable", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,

dataStruct: false as boolean,
},
type: "table",
Expand Down Expand Up @@ -127,7 +127,7 @@ describe("resolveTable", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,

dataStruct: true as boolean,
},
type: "table",
Expand Down
18 changes: 7 additions & 11 deletions packages/store/ts/config/v2/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,22 @@ export type resolveTableCodegen<input extends TableInput> = evaluate<{
? undefined extends input["codegen"][key]
? key extends "dataStruct"
? boolean
: key extends "outputDirectory"
? string
: key extends keyof TABLE_CODEGEN_DEFAULTS
? TABLE_CODEGEN_DEFAULTS[key]
: never
: key extends keyof TABLE_CODEGEN_DEFAULTS
? TABLE_CODEGEN_DEFAULTS[key]
: never
: input["codegen"][key]
: // dataStruct isn't narrowed, because its value is conditional on the number of value schema fields
key extends "dataStruct"
? boolean
: key extends "outputDirectory"
? string
: key extends keyof TABLE_CODEGEN_DEFAULTS
? TABLE_CODEGEN_DEFAULTS[key]
: never;
: key extends keyof TABLE_CODEGEN_DEFAULTS
? TABLE_CODEGEN_DEFAULTS[key]
: never;
}>;

export function resolveTableCodegen<input extends TableInput>(input: input): resolveTableCodegen<input> {
const options = input.codegen;
return {
outputDirectory: get(options, "outputDirectory") ?? "tables",
outputDirectory: get(options, "outputDirectory") ?? TABLE_CODEGEN_DEFAULTS.outputDirectory,
tableIdArgument: get(options, "tableIdArgument") ?? TABLE_CODEGEN_DEFAULTS.tableIdArgument,
storeArgument: get(options, "storeArgument") ?? TABLE_CODEGEN_DEFAULTS.storeArgument,
// dataStruct is true if there are at least 2 value fields
Expand Down
20 changes: 2 additions & 18 deletions packages/world/ts/config/v2/world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ describe("defineWorld", () => {
key: ["id"],
name: "ExampleTable",
namespace: "ExampleNamespace",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -128,11 +124,7 @@ describe("defineWorld", () => {
key: ["id"],
name: "ExampleTable",
namespace: "ExampleNamespace",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -244,7 +236,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
type: "table",
Expand Down Expand Up @@ -298,7 +289,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
type: "table",
Expand Down Expand Up @@ -351,7 +341,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
type: "table",
Expand Down Expand Up @@ -406,7 +395,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
type: "table",
Expand All @@ -433,7 +421,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
type: "table",
Expand Down Expand Up @@ -492,7 +479,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
type: "table",
Expand All @@ -519,7 +505,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
type: "table",
Expand Down Expand Up @@ -634,7 +619,6 @@ describe("defineWorld", () => {
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
type: "table",
Expand Down
36 changes: 6 additions & 30 deletions packages/world/ts/config/v2/worldWithShorthands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ describe("defineWorldWithShorthands", () => {
key: ["id"],
name: "ExampleTable",
namespace: "ExampleNamespace",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -124,11 +120,7 @@ describe("defineWorldWithShorthands", () => {
key: ["id"],
name: "ExampleTable",
namespace: "ExampleNamespace",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -174,11 +166,7 @@ describe("defineWorldWithShorthands", () => {
key: ["id"],
name: "Name",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -217,11 +205,7 @@ describe("defineWorldWithShorthands", () => {
key: ["id"],
name: "Name",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: false as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: false as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -262,11 +246,7 @@ describe("defineWorldWithShorthands", () => {
key: ["id"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down Expand Up @@ -307,11 +287,7 @@ describe("defineWorldWithShorthands", () => {
key: ["id"],
name: "Example",
namespace: "",
codegen: {
...TABLE_CODEGEN_DEFAULTS,
outputDirectory: "tables" as string,
dataStruct: true as boolean,
},
codegen: { ...TABLE_CODEGEN_DEFAULTS, dataStruct: true as boolean },
type: "table",
deploy: TABLE_DEPLOY_DEFAULTS,
},
Expand Down

0 comments on commit 0937cd6

Please sign in to comment.