@gtkx/config 0.21.0 → 1.0.0-rc.1

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.
Files changed (77) hide show
  1. package/README.md +137 -82
  2. package/dist/config.d.ts +76 -35
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +76 -83
  5. package/dist/config.js.map +1 -1
  6. package/dist/element-props.d.ts +180 -0
  7. package/dist/element-props.d.ts.map +1 -0
  8. package/dist/element-props.js +154 -0
  9. package/dist/element-props.js.map +1 -0
  10. package/dist/index.d.ts +3 -10
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -8
  13. package/dist/index.js.map +1 -1
  14. package/dist/internal.d.ts +3 -0
  15. package/dist/internal.d.ts.map +1 -0
  16. package/dist/internal.js +3 -0
  17. package/dist/internal.js.map +1 -0
  18. package/dist/loader.d.ts +19 -15
  19. package/dist/loader.d.ts.map +1 -1
  20. package/dist/loader.js +25 -39
  21. package/dist/loader.js.map +1 -1
  22. package/dist/virtual.d.ts +2 -4
  23. package/dist/virtual.d.ts.map +1 -1
  24. package/dist/virtual.js +2 -14
  25. package/dist/virtual.js.map +1 -1
  26. package/dist/vite-plugin.d.ts +16 -0
  27. package/dist/vite-plugin.d.ts.map +1 -0
  28. package/dist/vite-plugin.js +32 -0
  29. package/dist/vite-plugin.js.map +1 -0
  30. package/env.d.ts +4 -22
  31. package/package.json +20 -7
  32. package/src/config.ts +134 -144
  33. package/src/element-props.ts +248 -0
  34. package/src/index.ts +14 -82
  35. package/src/internal.ts +2 -0
  36. package/src/loader.ts +36 -56
  37. package/src/virtual.ts +3 -32
  38. package/src/vite-plugin.ts +37 -0
  39. package/dist/bundled-modules.d.ts +0 -2
  40. package/dist/bundled-modules.d.ts.map +0 -1
  41. package/dist/bundled-modules.js +0 -2
  42. package/dist/bundled-modules.js.map +0 -1
  43. package/dist/data-dir.d.ts +0 -4
  44. package/dist/data-dir.d.ts.map +0 -1
  45. package/dist/data-dir.js +0 -37
  46. package/dist/data-dir.js.map +0 -1
  47. package/dist/plugin.d.ts +0 -9
  48. package/dist/plugin.d.ts.map +0 -1
  49. package/dist/plugin.js +0 -24
  50. package/dist/plugin.js.map +0 -1
  51. package/dist/runtime.d.ts +0 -22
  52. package/dist/runtime.d.ts.map +0 -1
  53. package/dist/runtime.js +0 -22
  54. package/dist/runtime.js.map +0 -1
  55. package/dist/table-rules-ir.d.ts +0 -36
  56. package/dist/table-rules-ir.d.ts.map +0 -1
  57. package/dist/table-rules-ir.js +0 -2
  58. package/dist/table-rules-ir.js.map +0 -1
  59. package/dist/table-schema.d.ts +0 -107
  60. package/dist/table-schema.d.ts.map +0 -1
  61. package/dist/table-schema.js +0 -199
  62. package/dist/table-schema.js.map +0 -1
  63. package/dist/validators.d.ts +0 -4
  64. package/dist/validators.d.ts.map +0 -1
  65. package/dist/validators.js +0 -10
  66. package/dist/validators.js.map +0 -1
  67. package/dist/wrapper-protocol.d.ts +0 -12
  68. package/dist/wrapper-protocol.d.ts.map +0 -1
  69. package/dist/wrapper-protocol.js +0 -12
  70. package/dist/wrapper-protocol.js.map +0 -1
  71. package/src/bundled-modules.ts +0 -1
  72. package/src/data-dir.ts +0 -39
  73. package/src/plugin.ts +0 -30
  74. package/src/table-rules-ir.ts +0 -42
  75. package/src/table-schema.ts +0 -342
  76. package/src/validators.ts +0 -15
  77. package/src/wrapper-protocol.ts +0 -21
@@ -0,0 +1,180 @@
1
+ import { z } from "zod";
2
+ declare const ARG_REFS: readonly ["child", "item", "index", "sibling", "adopted"];
3
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
4
+ [key: string]: JsonValue;
5
+ };
6
+ /**
7
+ * Named reference to a value available while invoking a {@link Call}: the child
8
+ * widget, the current list item, its index, the preceding sibling, or the
9
+ * adopted instance a container returned for the child.
10
+ */
11
+ export type ArgRef = (typeof ARG_REFS)[number];
12
+ /**
13
+ * A single argument passed to a method {@link Call}: an {@link ArgRef}, a value
14
+ * read from a React prop (`{ prop }`), a field read off the current item with an
15
+ * optional fallback (`{ field, or }`), or a constant (`{ literal }`).
16
+ */
17
+ export type Arg = ArgRef | {
18
+ prop: string;
19
+ } | {
20
+ field: string;
21
+ or?: JsonValue;
22
+ } | {
23
+ literal: JsonValue;
24
+ };
25
+ /**
26
+ * A GObject method invocation: either a bare method name called with default
27
+ * arguments, or a method name paired with an explicit list of {@link Arg}s.
28
+ */
29
+ export type Call = string | {
30
+ method: string;
31
+ args: Arg[];
32
+ };
33
+ export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
34
+ type IssuePath = Array<string | number>;
35
+ export declare const rawIssue: (input: unknown, path: IssuePath, message: string, standalone?: boolean) => {
36
+ code: "custom";
37
+ input: unknown;
38
+ path: IssuePath;
39
+ message: string;
40
+ continue: true;
41
+ params?: {
42
+ standalone: boolean;
43
+ };
44
+ };
45
+ declare const containerSchema: z.ZodObject<{
46
+ kind: z.ZodLiteral<"container">;
47
+ prop: z.ZodString;
48
+ child: z.ZodString;
49
+ append: z.ZodOptional<z.ZodCustom<Call, Call>>;
50
+ remove: z.ZodOptional<z.ZodCustom<Call, Call>>;
51
+ insert: z.ZodOptional<z.ZodCustom<Call, Call>>;
52
+ reorder: z.ZodOptional<z.ZodCustom<Call, Call>>;
53
+ autowrap: z.ZodOptional<z.ZodString>;
54
+ adopt: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodString]>>;
55
+ }, z.core.$strict>;
56
+ declare const valueSchema: z.ZodObject<{
57
+ kind: z.ZodLiteral<"value">;
58
+ prop: z.ZodString;
59
+ call: z.ZodCustom<Call, Call>;
60
+ after: z.ZodOptional<z.ZodString>;
61
+ }, z.core.$strict>;
62
+ declare const controlledTextSchema: z.ZodObject<{
63
+ kind: z.ZodLiteral<"controlled-text">;
64
+ prop: z.ZodString;
65
+ }, z.core.$strict>;
66
+ declare const lazySchema: z.ZodObject<{
67
+ kind: z.ZodLiteral<"lazy">;
68
+ prop: z.ZodString;
69
+ lookup: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strict>;
71
+ declare const listSchema: z.ZodObject<{
72
+ kind: z.ZodLiteral<"list">;
73
+ prop: z.ZodString;
74
+ add: z.ZodUnion<readonly [z.ZodCustom<Call, Call>, z.ZodArray<z.ZodCustom<Call, Call>>]>;
75
+ remove: z.ZodOptional<z.ZodCustom<Call, Call>>;
76
+ clear: z.ZodOptional<z.ZodCustom<Call, Call>>;
77
+ }, z.core.$strict>;
78
+ declare const elementPropSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
79
+ kind: z.ZodLiteral<"container">;
80
+ prop: z.ZodString;
81
+ child: z.ZodString;
82
+ append: z.ZodOptional<z.ZodCustom<Call, Call>>;
83
+ remove: z.ZodOptional<z.ZodCustom<Call, Call>>;
84
+ insert: z.ZodOptional<z.ZodCustom<Call, Call>>;
85
+ reorder: z.ZodOptional<z.ZodCustom<Call, Call>>;
86
+ autowrap: z.ZodOptional<z.ZodString>;
87
+ adopt: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodString]>>;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ kind: z.ZodLiteral<"value">;
90
+ prop: z.ZodString;
91
+ call: z.ZodCustom<Call, Call>;
92
+ after: z.ZodOptional<z.ZodString>;
93
+ }, z.core.$strict>, z.ZodObject<{
94
+ kind: z.ZodLiteral<"controlled-text">;
95
+ prop: z.ZodString;
96
+ }, z.core.$strict>, z.ZodObject<{
97
+ kind: z.ZodLiteral<"lazy">;
98
+ prop: z.ZodString;
99
+ lookup: z.ZodOptional<z.ZodString>;
100
+ }, z.core.$strict>, z.ZodObject<{
101
+ kind: z.ZodLiteral<"list">;
102
+ prop: z.ZodString;
103
+ add: z.ZodUnion<readonly [z.ZodCustom<Call, Call>, z.ZodArray<z.ZodCustom<Call, Call>>]>;
104
+ remove: z.ZodOptional<z.ZodCustom<Call, Call>>;
105
+ clear: z.ZodOptional<z.ZodCustom<Call, Call>>;
106
+ }, z.core.$strict>], "kind">;
107
+ export declare const elementPropsSchema: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
108
+ kind: z.ZodLiteral<"container">;
109
+ prop: z.ZodString;
110
+ child: z.ZodString;
111
+ append: z.ZodOptional<z.ZodCustom<Call, Call>>;
112
+ remove: z.ZodOptional<z.ZodCustom<Call, Call>>;
113
+ insert: z.ZodOptional<z.ZodCustom<Call, Call>>;
114
+ reorder: z.ZodOptional<z.ZodCustom<Call, Call>>;
115
+ autowrap: z.ZodOptional<z.ZodString>;
116
+ adopt: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodString]>>;
117
+ }, z.core.$strict>, z.ZodObject<{
118
+ kind: z.ZodLiteral<"value">;
119
+ prop: z.ZodString;
120
+ call: z.ZodCustom<Call, Call>;
121
+ after: z.ZodOptional<z.ZodString>;
122
+ }, z.core.$strict>, z.ZodObject<{
123
+ kind: z.ZodLiteral<"controlled-text">;
124
+ prop: z.ZodString;
125
+ }, z.core.$strict>, z.ZodObject<{
126
+ kind: z.ZodLiteral<"lazy">;
127
+ prop: z.ZodString;
128
+ lookup: z.ZodOptional<z.ZodString>;
129
+ }, z.core.$strict>, z.ZodObject<{
130
+ kind: z.ZodLiteral<"list">;
131
+ prop: z.ZodString;
132
+ add: z.ZodUnion<readonly [z.ZodCustom<Call, Call>, z.ZodArray<z.ZodCustom<Call, Call>>]>;
133
+ remove: z.ZodOptional<z.ZodCustom<Call, Call>>;
134
+ clear: z.ZodOptional<z.ZodCustom<Call, Call>>;
135
+ }, z.core.$strict>], "kind">>>;
136
+ /**
137
+ * Rule describing how children of a given type are attached to and removed from a
138
+ * container element. `prop` is the React prop holding the children and `child` the
139
+ * child GObject type. `append`/`remove` add and remove a child, `insert` places
140
+ * one at an index or after a sibling, `reorder` moves an existing child, `autowrap`
141
+ * names a widget type each child is wrapped in before attaching, and `adopt` marks
142
+ * pre-existing children as adopted (`true`) or names the getter returning them.
143
+ */
144
+ export type ContainerProp = z.infer<typeof containerSchema>;
145
+ /**
146
+ * Rule that applies a scalar prop value by invoking `call` whenever the value
147
+ * changes, optionally running the method named by `after` once it is set.
148
+ */
149
+ export type ValueProp = z.infer<typeof valueSchema>;
150
+ /**
151
+ * Rule for a controlled text prop: `prop` is written directly to the GObject
152
+ * property and kept in sync with the element's own edits.
153
+ */
154
+ export type ControlledTextProp = z.infer<typeof controlledTextSchema>;
155
+ /**
156
+ * Rule for a prop applied after construction rather than at construction time,
157
+ * optionally guarded by `lookup`, a method that must succeed for the value before
158
+ * it is assigned.
159
+ */
160
+ export type LazyProp = z.infer<typeof lazySchema>;
161
+ /**
162
+ * Rule mapping an array prop to method calls: `add` runs per added item (a single
163
+ * call, or a sequence of calls applied in order when one item needs several), `remove`
164
+ * per removed item, and `clear` empties the collection before re-adding.
165
+ */
166
+ export type ListProp = z.infer<typeof listSchema>;
167
+ /**
168
+ * Any prop rule applied directly to an element instance rather than through
169
+ * container child attachment: a {@link ValueProp}, {@link ControlledTextProp},
170
+ * {@link LazyProp}, or {@link ListProp}.
171
+ */
172
+ export type AppliedProp = ValueProp | ControlledTextProp | LazyProp | ListProp;
173
+ /**
174
+ * A single entry in an element's prop mapping, discriminated by `kind`: a
175
+ * container, value, controlled-text, lazy, or list rule.
176
+ */
177
+ export type ElementProp = z.infer<typeof elementPropSchema>;
178
+ export declare const configError: (error: z.ZodError) => Error;
179
+ export {};
180
+ //# sourceMappingURL=element-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-props.d.ts","sourceRoot":"","sources":["../src/element-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,QAAQ,YAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAE3E,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EAAE,GAA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AAe,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAwB5D,eAAO,MAAM,WAAW,UAAW,CAAC,CAAC,QAAQ,KAAG,KAI/C,CAAC"}
@@ -0,0 +1,154 @@
1
+ import { z } from "zod";
2
+ const ARG_REFS = ["child", "item", "index", "sibling", "adopted"];
3
+ const NAME_MESSAGE = "must be a non-empty string";
4
+ const JSON_MESSAGE = "must be a JSON-serializable value";
5
+ const ARG_MESSAGE = "must be one of: reference name, { prop }, { field }, { literal }";
6
+ const ARG_REF_SET = new Set(ARG_REFS);
7
+ export const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
8
+ const isJsonValue = (value) => {
9
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
10
+ return true;
11
+ }
12
+ if (Array.isArray(value))
13
+ return value.every(isJsonValue);
14
+ if (isRecord(value))
15
+ return Object.values(value).every(isJsonValue);
16
+ return false;
17
+ };
18
+ export const rawIssue = (input, path, message, standalone = false) => ({
19
+ code: "custom",
20
+ input,
21
+ path,
22
+ message,
23
+ continue: true,
24
+ ...(standalone ? { params: { standalone: true } } : {}),
25
+ });
26
+ const unknownKeyIssues = (value, allowed) => Object.keys(value)
27
+ .filter((key) => !allowed.includes(key))
28
+ .map((key) => ({ path: [key], message: "is not a recognized key" }));
29
+ const requireName = (value) => typeof value === "string" && value.length > 0;
30
+ const collectPropArgIssues = (value) => {
31
+ const issues = unknownKeyIssues(value, ["prop"]);
32
+ if (!requireName(value.prop))
33
+ issues.push({ path: ["prop"], message: NAME_MESSAGE });
34
+ return issues;
35
+ };
36
+ const collectFieldArgIssues = (value) => {
37
+ const issues = unknownKeyIssues(value, ["field", "or"]);
38
+ if (!requireName(value.field))
39
+ issues.push({ path: ["field"], message: NAME_MESSAGE });
40
+ if ("or" in value && !isJsonValue(value.or))
41
+ issues.push({ path: ["or"], message: JSON_MESSAGE });
42
+ return issues;
43
+ };
44
+ const collectLiteralArgIssues = (value) => {
45
+ const issues = unknownKeyIssues(value, ["literal"]);
46
+ if (!isJsonValue(value.literal))
47
+ issues.push({ path: ["literal"], message: JSON_MESSAGE });
48
+ return issues;
49
+ };
50
+ const collectArgIssues = (value) => {
51
+ if (typeof value === "string") {
52
+ return ARG_REF_SET.has(value) ? [] : [{ path: [], message: `has unknown reference "${value}"` }];
53
+ }
54
+ if (!isRecord(value))
55
+ return [{ path: [], message: ARG_MESSAGE }];
56
+ if ("prop" in value)
57
+ return collectPropArgIssues(value);
58
+ if ("field" in value)
59
+ return collectFieldArgIssues(value);
60
+ if ("literal" in value)
61
+ return collectLiteralArgIssues(value);
62
+ return [{ path: [], message: ARG_MESSAGE }];
63
+ };
64
+ const collectArgsIssues = (args) => args.flatMap((arg, index) => collectArgIssues(arg).map((issue) => ({ path: ["args", index, ...issue.path], message: issue.message })));
65
+ const collectCallIssues = (value) => {
66
+ if (typeof value === "string")
67
+ return value.length === 0 ? [{ path: [], message: NAME_MESSAGE }] : [];
68
+ if (!isRecord(value))
69
+ return [{ path: [], message: "must be an object" }];
70
+ const issues = unknownKeyIssues(value, ["method", "args"]);
71
+ if (!requireName(value.method))
72
+ issues.push({ path: ["method"], message: NAME_MESSAGE });
73
+ if (!Array.isArray(value.args))
74
+ issues.push({ path: ["args"], message: "must be an array" });
75
+ else
76
+ issues.push(...collectArgsIssues(value.args));
77
+ return issues;
78
+ };
79
+ const callSchema = z.custom().check((ctx) => {
80
+ ctx.issues.push(...collectCallIssues(ctx.value).map((issue) => rawIssue(ctx.value, issue.path, issue.message)));
81
+ });
82
+ const nameSchema = z.string({ error: NAME_MESSAGE }).min(1, { error: NAME_MESSAGE });
83
+ const adoptSchema = z.union([z.literal(true), nameSchema], {
84
+ error: "must be `true` or the name of a getter method",
85
+ });
86
+ const containerSchema = z.strictObject({
87
+ kind: z.literal("container"),
88
+ prop: nameSchema,
89
+ child: nameSchema,
90
+ append: callSchema.optional(),
91
+ remove: callSchema.optional(),
92
+ insert: callSchema.optional(),
93
+ reorder: callSchema.optional(),
94
+ autowrap: nameSchema.optional(),
95
+ adopt: adoptSchema.optional(),
96
+ });
97
+ const valueSchema = z.strictObject({
98
+ kind: z.literal("value"),
99
+ prop: nameSchema,
100
+ call: callSchema,
101
+ after: nameSchema.optional(),
102
+ });
103
+ const controlledTextSchema = z.strictObject({
104
+ kind: z.literal("controlled-text"),
105
+ prop: nameSchema,
106
+ });
107
+ const lazySchema = z.strictObject({
108
+ kind: z.literal("lazy"),
109
+ prop: nameSchema,
110
+ lookup: nameSchema.optional(),
111
+ });
112
+ const listSchema = z.strictObject({
113
+ kind: z.literal("list"),
114
+ prop: nameSchema,
115
+ add: z.union([callSchema, z.array(callSchema).min(1)]),
116
+ remove: callSchema.optional(),
117
+ clear: callSchema.optional(),
118
+ });
119
+ const elementPropSchema = z
120
+ .discriminatedUnion("kind", [containerSchema, valueSchema, controlledTextSchema, lazySchema, listSchema], {
121
+ error: "must be one of container, value, controlled-text, lazy, list",
122
+ })
123
+ .check((ctx) => {
124
+ const prop = ctx.value;
125
+ if (prop.kind === "container" && prop.append === undefined && prop.remove === undefined) {
126
+ ctx.issues.push(rawIssue(prop, [], "must define at least one of `append` or `remove`"));
127
+ }
128
+ });
129
+ export const elementPropsSchema = z.record(nameSchema, z.array(elementPropSchema));
130
+ const CONFIG_PREFIX = "gtkx.config.ts:";
131
+ const dottedPath = (segments) => segments.reduce((acc, segment) => {
132
+ if (typeof segment === "number")
133
+ return `${acc}[${segment}]`;
134
+ return acc === "" ? String(segment) : `${acc}.${String(segment)}`;
135
+ }, "");
136
+ const isStandaloneIssue = (issue) => "params" in issue && isRecord(issue.params) && issue.params.standalone === true;
137
+ const formatIssue = (issue, fullPath) => {
138
+ if (issue.code === "unrecognized_keys") {
139
+ const [key] = issue.keys;
140
+ const path = dottedPath(key === undefined ? fullPath : [...fullPath, key]);
141
+ return `${CONFIG_PREFIX} \`${path}\` is not a recognized key`;
142
+ }
143
+ if (isStandaloneIssue(issue))
144
+ return `${CONFIG_PREFIX} ${issue.message}`;
145
+ const path = dottedPath(fullPath);
146
+ return path === "" ? `${CONFIG_PREFIX} ${issue.message}` : `${CONFIG_PREFIX} \`${path}\` ${issue.message}`;
147
+ };
148
+ export const configError = (error) => {
149
+ const issue = error.issues[0];
150
+ if (issue === undefined)
151
+ return new Error(`${CONFIG_PREFIX} invalid configuration`);
152
+ return new Error(formatIssue(issue, issue.path));
153
+ };
154
+ //# sourceMappingURL=element-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-props.js","sourceRoot":"","sources":["../src/element-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAwB3E,MAAM,YAAY,GAAG,4BAA4B,CAAC;AAElD,MAAM,YAAY,GAAG,mCAAmC,CAAC;AAEzD,MAAM,WAAW,GAAG,kEAAkE,CAAC;AAEvF,MAAM,WAAW,GAAgB,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEnD,MA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AAa,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,aAAa,MAAM,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;AAC/G,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAS,EAAE;IACpD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,aAAa,wBAAwB,CAAC,CAAC;IACpF,OAAO,IAAI,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nconst ARG_REFS = [\"child\", \"item\", \"index\", \"sibling\", \"adopted\"] as const;\n\ntype JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\n\n/**\n * Named reference to a value available while invoking a {@link Call}: the child\n * widget, the current list item, its index, the preceding sibling, or the\n * adopted instance a container returned for the child.\n */\nexport type ArgRef = (typeof ARG_REFS)[number];\n\n/**\n * A single argument passed to a method {@link Call}: an {@link ArgRef}, a value\n * read from a React prop (`{ prop }`), a field read off the current item with an\n * optional fallback (`{ field, or }`), or a constant (`{ literal }`).\n */\nexport type Arg = ArgRef | { prop: string } | { field: string; or?: JsonValue } | { literal: JsonValue };\n\n/**\n * A GObject method invocation: either a bare method name called with default\n * arguments, or a method name paired with an explicit list of {@link Arg}s.\n */\nexport type Call = string | { method: string; args: Arg[] };\n\nconst NAME_MESSAGE = \"must be a non-empty string\";\n\nconst JSON_MESSAGE = \"must be a JSON-serializable value\";\n\nconst ARG_MESSAGE = \"must be one of: reference name, { prop }, { field }, { literal }\";\n\nconst ARG_REF_SET: Set<string> = new Set(ARG_REFS);\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isJsonValue = (value: unknown): boolean => {\n if (value === null || typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return true;\n }\n if (Array.isArray(value)) return value.every(isJsonValue);\n if (isRecord(value)) return Object.values(value).every(isJsonValue);\n return false;\n};\n\ntype IssuePath = Array<string | number>;\n\ntype CollectedIssue = { path: IssuePath; message: string };\n\nexport const rawIssue = (input: unknown, path: IssuePath, message: string, standalone = false) => ({\n code: \"custom\" as const,\n input,\n path,\n message,\n continue: true as const,\n ...(standalone ? { params: { standalone: true } } : {}),\n});\n\nconst unknownKeyIssues = (value: Record<string, unknown>, allowed: string[]): CollectedIssue[] =>\n Object.keys(value)\n .filter((key) => !allowed.includes(key))\n .map((key) => ({ path: [key], message: \"is not a recognized key\" }));\n\nconst requireName = (value: unknown): boolean => typeof value === \"string\" && value.length > 0;\n\nconst collectPropArgIssues = (value: Record<string, unknown>): CollectedIssue[] => {\n const issues = unknownKeyIssues(value, [\"prop\"]);\n if (!requireName(value.prop)) issues.push({ path: [\"prop\"], message: NAME_MESSAGE });\n return issues;\n};\n\nconst collectFieldArgIssues = (value: Record<string, unknown>): CollectedIssue[] => {\n const issues = unknownKeyIssues(value, [\"field\", \"or\"]);\n if (!requireName(value.field)) issues.push({ path: [\"field\"], message: NAME_MESSAGE });\n if (\"or\" in value && !isJsonValue(value.or)) issues.push({ path: [\"or\"], message: JSON_MESSAGE });\n return issues;\n};\n\nconst collectLiteralArgIssues = (value: Record<string, unknown>): CollectedIssue[] => {\n const issues = unknownKeyIssues(value, [\"literal\"]);\n if (!isJsonValue(value.literal)) issues.push({ path: [\"literal\"], message: JSON_MESSAGE });\n return issues;\n};\n\nconst collectArgIssues = (value: unknown): CollectedIssue[] => {\n if (typeof value === \"string\") {\n return ARG_REF_SET.has(value) ? [] : [{ path: [], message: `has unknown reference \"${value}\"` }];\n }\n if (!isRecord(value)) return [{ path: [], message: ARG_MESSAGE }];\n if (\"prop\" in value) return collectPropArgIssues(value);\n if (\"field\" in value) return collectFieldArgIssues(value);\n if (\"literal\" in value) return collectLiteralArgIssues(value);\n return [{ path: [], message: ARG_MESSAGE }];\n};\n\nconst collectArgsIssues = (args: unknown[]): CollectedIssue[] =>\n args.flatMap((arg, index) =>\n collectArgIssues(arg).map((issue) => ({ path: [\"args\", index, ...issue.path], message: issue.message })),\n );\n\nconst collectCallIssues = (value: unknown): CollectedIssue[] => {\n if (typeof value === \"string\") return value.length === 0 ? [{ path: [], message: NAME_MESSAGE }] : [];\n if (!isRecord(value)) return [{ path: [], message: \"must be an object\" }];\n const issues = unknownKeyIssues(value, [\"method\", \"args\"]);\n if (!requireName(value.method)) issues.push({ path: [\"method\"], message: NAME_MESSAGE });\n if (!Array.isArray(value.args)) issues.push({ path: [\"args\"], message: \"must be an array\" });\n else issues.push(...collectArgsIssues(value.args));\n return issues;\n};\n\nconst callSchema = z.custom<Call>().check((ctx) => {\n ctx.issues.push(...collectCallIssues(ctx.value).map((issue) => rawIssue(ctx.value, issue.path, issue.message)));\n});\n\nconst nameSchema = z.string({ error: NAME_MESSAGE }).min(1, { error: NAME_MESSAGE });\n\nconst adoptSchema = z.union([z.literal(true), nameSchema], {\n error: \"must be `true` or the name of a getter method\",\n});\n\nconst containerSchema = z.strictObject({\n kind: z.literal(\"container\"),\n prop: nameSchema,\n child: nameSchema,\n append: callSchema.optional(),\n remove: callSchema.optional(),\n insert: callSchema.optional(),\n reorder: callSchema.optional(),\n autowrap: nameSchema.optional(),\n adopt: adoptSchema.optional(),\n});\n\nconst valueSchema = z.strictObject({\n kind: z.literal(\"value\"),\n prop: nameSchema,\n call: callSchema,\n after: nameSchema.optional(),\n});\n\nconst controlledTextSchema = z.strictObject({\n kind: z.literal(\"controlled-text\"),\n prop: nameSchema,\n});\n\nconst lazySchema = z.strictObject({\n kind: z.literal(\"lazy\"),\n prop: nameSchema,\n lookup: nameSchema.optional(),\n});\n\nconst listSchema = z.strictObject({\n kind: z.literal(\"list\"),\n prop: nameSchema,\n add: z.union([callSchema, z.array(callSchema).min(1)]),\n remove: callSchema.optional(),\n clear: callSchema.optional(),\n});\n\nconst elementPropSchema = z\n .discriminatedUnion(\"kind\", [containerSchema, valueSchema, controlledTextSchema, lazySchema, listSchema], {\n error: \"must be one of container, value, controlled-text, lazy, list\",\n })\n .check((ctx) => {\n const prop = ctx.value;\n if (prop.kind === \"container\" && prop.append === undefined && prop.remove === undefined) {\n ctx.issues.push(rawIssue(prop, [], \"must define at least one of `append` or `remove`\"));\n }\n });\n\nexport const elementPropsSchema = z.record(nameSchema, z.array(elementPropSchema));\n\n/**\n * Rule describing how children of a given type are attached to and removed from a\n * container element. `prop` is the React prop holding the children and `child` the\n * child GObject type. `append`/`remove` add and remove a child, `insert` places\n * one at an index or after a sibling, `reorder` moves an existing child, `autowrap`\n * names a widget type each child is wrapped in before attaching, and `adopt` marks\n * pre-existing children as adopted (`true`) or names the getter returning them.\n */\nexport type ContainerProp = z.infer<typeof containerSchema>;\n\n/**\n * Rule that applies a scalar prop value by invoking `call` whenever the value\n * changes, optionally running the method named by `after` once it is set.\n */\nexport type ValueProp = z.infer<typeof valueSchema>;\n\n/**\n * Rule for a controlled text prop: `prop` is written directly to the GObject\n * property and kept in sync with the element's own edits.\n */\nexport type ControlledTextProp = z.infer<typeof controlledTextSchema>;\n\n/**\n * Rule for a prop applied after construction rather than at construction time,\n * optionally guarded by `lookup`, a method that must succeed for the value before\n * it is assigned.\n */\nexport type LazyProp = z.infer<typeof lazySchema>;\n\n/**\n * Rule mapping an array prop to method calls: `add` runs per added item (a single\n * call, or a sequence of calls applied in order when one item needs several), `remove`\n * per removed item, and `clear` empties the collection before re-adding.\n */\nexport type ListProp = z.infer<typeof listSchema>;\n\n/**\n * Any prop rule applied directly to an element instance rather than through\n * container child attachment: a {@link ValueProp}, {@link ControlledTextProp},\n * {@link LazyProp}, or {@link ListProp}.\n */\nexport type AppliedProp = ValueProp | ControlledTextProp | LazyProp | ListProp;\n\n/**\n * A single entry in an element's prop mapping, discriminated by `kind`: a\n * container, value, controlled-text, lazy, or list rule.\n */\nexport type ElementProp = z.infer<typeof elementPropSchema>;\n\nconst CONFIG_PREFIX = \"gtkx.config.ts:\";\n\nconst dottedPath = (segments: PropertyKey[]): string =>\n segments.reduce<string>((acc, segment) => {\n if (typeof segment === \"number\") return `${acc}[${segment}]`;\n return acc === \"\" ? String(segment) : `${acc}.${String(segment)}`;\n }, \"\");\n\nconst isStandaloneIssue = (issue: z.core.$ZodIssue): boolean =>\n \"params\" in issue && isRecord(issue.params) && issue.params.standalone === true;\n\nconst formatIssue = (issue: z.core.$ZodIssue, fullPath: PropertyKey[]): string => {\n if (issue.code === \"unrecognized_keys\") {\n const [key] = issue.keys;\n const path = dottedPath(key === undefined ? fullPath : [...fullPath, key]);\n return `${CONFIG_PREFIX} \\`${path}\\` is not a recognized key`;\n }\n if (isStandaloneIssue(issue)) return `${CONFIG_PREFIX} ${issue.message}`;\n const path = dottedPath(fullPath);\n return path === \"\" ? `${CONFIG_PREFIX} ${issue.message}` : `${CONFIG_PREFIX} \\`${path}\\` ${issue.message}`;\n};\n\nexport const configError = (error: z.ZodError): Error => {\n const issue = error.issues[0];\n if (issue === undefined) return new Error(`${CONFIG_PREFIX} invalid configuration`);\n return new Error(formatIssue(issue, issue.path));\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,4 @@
1
- export { gtkxBundledModulePatterns } from "./bundled-modules.js";
2
- export { defineConfig, GIR_NAMESPACE_PATTERN, type GtkxConfig, type GtkxConfigEnv, type GtkxConfigExport, type GtkxConfigFn, type GtkxConfigFnPromise, LIBRARIES_WILDCARD, mergeConfig, type ReactCompilerCompilationMode, type ReactCompilerOptions, type ReactCompilerPanicThreshold, type ResolvedGtkxConfig, type ResolvedReactCompilerOptions, resolveGtkxConfig, resolveReactCompilerOptions, validateGtkxConfig, } from "./config.js";
3
- export { DATA_IMPORT_KEY, DATA_IMPORT_PREFIX, resolveDataDir } from "./data-dir.js";
4
- export { createGtkxConfigLoader, type GtkxConfigLoader, GtkxConfigNotFoundError, type LoadedConfig, type LoadGtkxConfigOptions, type LoadResolvedGtkxConfigOptions, loadGtkxConfig, loadResolvedGtkxConfig, } from "./loader.js";
5
- export { createGtkxConfigPlugin, type GtkxConfigPluginOptions } from "./plugin.js";
6
- export type { AddMethodArg, AddMethodRule, PageMetaSetter, PropCondition, PropRule, SetterPropGroup, SetterPropStep, SignalPropRule, } from "./table-rules-ir.js";
7
- export type { ArrayPropRow, AttachShape, AttachShapeTable, AttachVerb, CallArg, CallStep, ConstructSetter, ConstructStep, ContainerPropRow, DetachGuard, ElementMapRule, MethodVerb, ObjectPropRow, OrderedInsertVerb, PerElementPropRows, PresenceCondition, UserTableRows, VerbArgs, VirtualPropRow, } from "./table-schema.js";
8
- export { CAMEL_CASE_NAME_PATTERN, PASCAL_CASE_NAME_PATTERN, validateArrayOf, } from "./validators.js";
9
- export { GTKX_CONFIG_VIRTUAL_ID, RESOLVED_GTKX_CONFIG_VIRTUAL_ID, renderGtkxConfigModule, type SerializedGtkxConfig, serializeGtkxConfig, } from "./virtual.js";
10
- export { BUFFER_TEXT_KIND, CONTAINER_PROP_KIND, LABEL_TEXT_KIND, LAYOUT_CHILD_KIND, META_OBJECT_KIND, OVERLAY_KIND, SLOT_KIND, TAB_LABEL_KIND, TEXT_ANCHOR_KIND, TEXT_PAINTABLE_KIND, WRAPPER_NODE_ELEMENT, } from "./wrapper-protocol.js";
1
+ export { type Config, defineConfig, mergeConfig, type ResolvedConfig, type ResolvedReactCompilerOptions, } from "./config.js";
2
+ export type { AppliedProp, Arg, ArgRef, Call, ContainerProp, ControlledTextProp, ElementProp, LazyProp, ListProp, ValueProp, } from "./element-props.js";
3
+ export { type LoadedConfig, loadConfig } from "./loader.js";
11
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAA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;AACtB,OAAO,EACH,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACvB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,MAAM,EACX,YAAY,EACZ,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,4BAA4B,GACpC,MAAM,aAAa,CAAC;AACrB,YAAY,EACR,WAAW,EACX,GAAG,EACH,MAAM,EACN,IAAI,EACJ,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,SAAS,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,9 +1,3 @@
1
- export { gtkxBundledModulePatterns } from "./bundled-modules.js";
2
- export { defineConfig, GIR_NAMESPACE_PATTERN, LIBRARIES_WILDCARD, mergeConfig, resolveGtkxConfig, resolveReactCompilerOptions, validateGtkxConfig, } from "./config.js";
3
- export { DATA_IMPORT_KEY, DATA_IMPORT_PREFIX, resolveDataDir } from "./data-dir.js";
4
- export { createGtkxConfigLoader, GtkxConfigNotFoundError, loadGtkxConfig, loadResolvedGtkxConfig, } from "./loader.js";
5
- export { createGtkxConfigPlugin } from "./plugin.js";
6
- export { CAMEL_CASE_NAME_PATTERN, PASCAL_CASE_NAME_PATTERN, validateArrayOf, } from "./validators.js";
7
- export { GTKX_CONFIG_VIRTUAL_ID, RESOLVED_GTKX_CONFIG_VIRTUAL_ID, renderGtkxConfigModule, serializeGtkxConfig, } from "./virtual.js";
8
- export { BUFFER_TEXT_KIND, CONTAINER_PROP_KIND, LABEL_TEXT_KIND, LAYOUT_CHILD_KIND, META_OBJECT_KIND, OVERLAY_KIND, SLOT_KIND, TAB_LABEL_KIND, TEXT_ANCHOR_KIND, TEXT_PAINTABLE_KIND, WRAPPER_NODE_ELEMENT, } from "./wrapper-protocol.js";
1
+ export { defineConfig, mergeConfig, } from "./config.js";
2
+ export { loadConfig } from "./loader.js";
9
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EACH,YAAY,EACZ,qBAAqB,EAMrB,kBAAkB,EAClB,WAAW,EAMX,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EACH,sBAAsB,EAEtB,uBAAuB,EAIvB,cAAc,EACd,sBAAsB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAgC,MAAM,aAAa,CAAC;AAgCnF,OAAO,EACH,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,sBAAsB,EACtB,+BAA+B,EAC/B,sBAAsB,EAEtB,mBAAmB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACvB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EACZ,WAAW,GAGd,MAAM,aAAa,CAAC;AAarB,OAAO,EAAqB,UAAU,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n type Config,\n defineConfig,\n mergeConfig,\n type ResolvedConfig,\n type ResolvedReactCompilerOptions,\n} from \"./config.js\";\nexport type {\n AppliedProp,\n Arg,\n ArgRef,\n Call,\n ContainerProp,\n ControlledTextProp,\n ElementProp,\n LazyProp,\n ListProp,\n ValueProp,\n} from \"./element-props.js\";\nexport { type LoadedConfig, loadConfig } from \"./loader.js\";\n"]}
@@ -0,0 +1,3 @@
1
+ export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD } from "./config.js";
2
+ export { type ConfigLoader, createConfigLoader } from "./loader.js";
3
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,KAAK,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD } from "./config.js";
2
+ export { createConfigLoader } from "./loader.js";
3
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAqB,kBAAkB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { GIR_LIBRARY_PATTERN, isValidApplicationId, LIBRARIES_WILDCARD } from \"./config.js\";\nexport { type ConfigLoader, createConfigLoader } from \"./loader.js\";\n"]}
package/dist/loader.d.ts CHANGED
@@ -1,20 +1,24 @@
1
- import { type GtkxConfig, type ResolvedGtkxConfig } from "./config.js";
1
+ import { type Config, type ResolvedConfig } from "./config.js";
2
+ /**
3
+ * Result of loading a `gtkx.config.ts` file: the parsed configuration, the
4
+ * resolved config file path (`undefined` when none was found), and the project
5
+ * root it was loaded from.
6
+ */
2
7
  export type LoadedConfig = {
3
- config: GtkxConfig;
8
+ config: Config;
4
9
  configFile: string | undefined;
5
- rootDir: string;
10
+ root: string;
6
11
  };
7
- export declare class GtkxConfigNotFoundError extends Error {
8
- constructor(cwd: string);
9
- }
10
- export type LoadGtkxConfigOptions = {
11
- mode?: string;
12
+ export type LoadConfigOptions = {
13
+ mode?: string | undefined;
12
14
  };
13
- export declare const loadGtkxConfig: (cwd: string, options?: LoadGtkxConfigOptions) => Promise<LoadedConfig>;
14
- export type LoadResolvedGtkxConfigOptions = LoadGtkxConfigOptions & {
15
- allowMissing?: boolean;
16
- };
17
- export declare const loadResolvedGtkxConfig: (cwd: string, options?: LoadResolvedGtkxConfigOptions) => Promise<ResolvedGtkxConfig>;
18
- export type GtkxConfigLoader = (cwd: string) => Promise<ResolvedGtkxConfig>;
19
- export declare const createGtkxConfigLoader: (options?: LoadResolvedGtkxConfigOptions) => GtkxConfigLoader;
15
+ /**
16
+ * Loads and validates the `gtkx.config.ts` file for a project, returning the
17
+ * parsed configuration together with the config file path and project root.
18
+ * @param cwd Directory from which to search for the configuration file.
19
+ * @param options Loading options, such as the environment mode.
20
+ */
21
+ export declare const loadConfig: (cwd: string, options?: LoadConfigOptions) => Promise<LoadedConfig>;
22
+ export type ConfigLoader = (cwd: string) => Promise<ResolvedConfig>;
23
+ export declare const createConfigLoader: (options?: LoadConfigOptions) => ConfigLoader;
20
24
  //# sourceMappingURL=loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAyC,MAAM,aAAa,CAAC;AAE9G,MAAM,MAAM,YAAY,GAAG;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU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G,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAEpE,eAAO,MAAM,kBAAkB,aAAa,iBAAiB,KAAQ,YAgBpE,CAAC"}
package/dist/loader.js CHANGED
@@ -1,59 +1,45 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
- import { loadConfig } from "c12";
4
- import { resolveGtkxConfig, validateGtkxConfig } from "./config.js";
5
- export class GtkxConfigNotFoundError extends Error {
6
- constructor(cwd) {
7
- super(`No gtkx.config.ts found in ${cwd}.\n` +
8
- `Create one with:\n` +
9
- `\n` +
10
- ` // gtkx.config.ts\n` +
11
- ` import { defineConfig } from "@gtkx/config";\n` +
12
- `\n` +
13
- ` export default defineConfig({\n` +
14
- ` libraries: ["Gtk-4.0", "Adw-1"],\n` +
15
- ` });\n`);
16
- this.name = "GtkxConfigNotFoundError";
17
- }
18
- }
19
- export const loadGtkxConfig = async (cwd, options = {}) => {
20
- const result = await loadConfig({
3
+ import { loadConfig as loadConfigFile } from "c12";
4
+ import { resolveConfig, validateConfig } from "./config.js";
5
+ /**
6
+ * Loads and validates the `gtkx.config.ts` file for a project, returning the
7
+ * parsed configuration together with the config file path and project root.
8
+ * @param cwd Directory from which to search for the configuration file.
9
+ * @param options Loading options, such as the environment mode.
10
+ */
11
+ export const loadConfig = async (cwd, options = {}) => {
12
+ const result = await loadConfigFile({
21
13
  name: "gtkx",
22
14
  cwd,
23
15
  rcFile: false,
24
16
  globalRc: false,
25
17
  packageJson: false,
26
18
  context: { mode: options.mode },
19
+ ...(options.mode !== undefined ? { envName: options.mode } : {}),
27
20
  });
28
- if (!result.configFile || !result.config || !existsSync(resolve(cwd, result.configFile))) {
29
- throw new GtkxConfigNotFoundError(cwd);
30
- }
31
- validateGtkxConfig(result.config);
21
+ const config = result.config;
22
+ const found = result.configFile !== undefined && existsSync(resolve(cwd, result.configFile));
23
+ if (found)
24
+ validateConfig(config);
32
25
  return {
33
- config: result.config,
34
- configFile: result.configFile,
35
- rootDir: result.cwd ?? cwd,
26
+ config,
27
+ configFile: found ? result.configFile : undefined,
28
+ root: result.cwd ?? cwd,
36
29
  };
37
30
  };
38
- export const loadResolvedGtkxConfig = async (cwd, options = {}) => {
39
- try {
40
- const { config } = await loadGtkxConfig(cwd, options.mode === undefined ? {} : { mode: options.mode });
41
- return resolveGtkxConfig(config);
42
- }
43
- catch (error) {
44
- if (options.allowMissing && error instanceof GtkxConfigNotFoundError) {
45
- return resolveGtkxConfig({});
46
- }
47
- throw error;
48
- }
49
- };
50
- export const createGtkxConfigLoader = (options = {}) => {
31
+ export const createConfigLoader = (options = {}) => {
51
32
  const cache = new Map();
33
+ const loadResolved = async (root) => {
34
+ const { config } = await loadConfig(root, options);
35
+ validateConfig(config);
36
+ return resolveConfig(config);
37
+ };
52
38
  return (cwd) => {
53
39
  const root = resolve(cwd);
54
40
  let pending = cache.get(root);
55
41
  if (!pending) {
56
- pending = loadResolvedGtkxConfig(root, options);
42
+ pending = loadResolved(root);
57
43
  cache.set(root, pending);
58
44
  }
59
45
  return pending;
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAA4C,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQ9G,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAC9C,YAAY,GAAW;QACnB,KAAK,CACD,8BAA8B,GAAG,KAAK;YAClC,oBAAoB;YACpB,IAAI;YACJ,uBAAuB;YACvB,kDAAkD;YAClD,IAAI;YACJ,mCAAmC;YACnC,0CAA0C;YAC1C,SAAS,CAChB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IAC1C,CAAC;CACJ;AAMD,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nB,CAAC,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { loadConfig as loadConfigFile } from \"c12\";\nimport { type Config, type ResolvedConfig, resolveConfig, validateConfig } from \"./config.js\";\n\n/**\n * Result of loading a `gtkx.config.ts` file: the parsed configuration, the\n * resolved config file path (`undefined` when none was found), and the project\n * root it was loaded from.\n */\nexport type LoadedConfig = {\n config: Config;\n configFile: string | undefined;\n root: string;\n};\n\nexport type LoadConfigOptions = {\n mode?: string | undefined;\n};\n\n/**\n * Loads and validates the `gtkx.config.ts` file for a project, returning the\n * parsed configuration together with the config file path and project root.\n * @param cwd Directory from which to search for the configuration file.\n * @param options Loading options, such as the environment mode.\n */\nexport const loadConfig = async (cwd: string, options: LoadConfigOptions = {}): Promise<LoadedConfig> => {\n const result = await loadConfigFile<Config>({\n name: \"gtkx\",\n cwd,\n rcFile: false,\n globalRc: false,\n packageJson: false,\n context: { mode: options.mode },\n ...(options.mode !== undefined ? { envName: options.mode } : {}),\n });\n\n const config = result.config;\n const found = result.configFile !== undefined && existsSync(resolve(cwd, result.configFile));\n\n if (found) validateConfig(config);\n\n return {\n config,\n configFile: found ? result.configFile : undefined,\n root: result.cwd ?? cwd,\n };\n};\n\nexport type ConfigLoader = (cwd: string) => Promise<ResolvedConfig>;\n\nexport const createConfigLoader = (options: LoadConfigOptions = {}): ConfigLoader => {\n const cache = new Map<string, Promise<ResolvedConfig>>();\n const loadResolved = async (root: string): Promise<ResolvedConfig> => {\n const { config } = await loadConfig(root, options);\n validateConfig(config);\n return resolveConfig(config);\n };\n return (cwd: string): Promise<ResolvedConfig> => {\n const root = resolve(cwd);\n let pending = cache.get(root);\n if (!pending) {\n pending = loadResolved(root);\n cache.set(root, pending);\n }\n return pending;\n };\n};\n"]}
package/dist/virtual.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import type { ResolvedGtkxConfig } from "./config.js";
1
+ import type { ResolvedConfig } from "./config.js";
2
2
  export declare const GTKX_CONFIG_VIRTUAL_ID = "virtual:gtkx-config";
3
3
  export declare const RESOLVED_GTKX_CONFIG_VIRTUAL_ID: string;
4
- export type SerializedGtkxConfig = Pick<ResolvedGtkxConfig, "libraries" | "girPath" | "applicationId" | "containerProps" | "arrayProps" | "objectProps" | "virtualProps" | "elementMap" | "reactCompiler">;
5
- export declare const serializeGtkxConfig: (config: ResolvedGtkxConfig) => SerializedGtkxConfig;
6
- export declare const renderGtkxConfigModule: (config: ResolvedGtkxConfig) => string;
4
+ export declare const renderConfigModule: (config: ResolvedConfig) => string;
7
5
  //# sourceMappingURL=virtual.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,sBAAsB,wBAAwB,CAAC;AAE5D,eAAO,MAAM,+BAA+B,EAAE,MAAsC,CAAC;AAIrF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACnC,kBAAkB,EAChB,WAAW,GACX,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,YAAY,GACZ,aAAa,GACb,cAAc,GACd,YAAY,GACZ,eAAe,CACpB,CAAC;AAIF,eAAO,MAAM,mBAAmB,GAAI,QAAQ,kBAAkB,KAAG,oBAU/D,CAAC;AAEH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,kBAAkB,KAAG,MAMpD,CAAC"}
1
+ {"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../src/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,sBAAsB,wBAAwB,CAAC;AAE5D,eAAO,MAAM,+BAA+B,EAAE,MAAsC,CAAC;AAIrF,eAAO,MAAM,kBAAkB,WAAY,cAAc,KAAG,MAI5C,CAAC"}