@proseql/cli 0.2.4

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +333 -0
  3. package/dist/commands/collections.d.ts +53 -0
  4. package/dist/commands/collections.d.ts.map +1 -0
  5. package/dist/commands/collections.js +145 -0
  6. package/dist/commands/collections.js.map +1 -0
  7. package/dist/commands/convert.d.ts +72 -0
  8. package/dist/commands/convert.d.ts.map +1 -0
  9. package/dist/commands/convert.js +340 -0
  10. package/dist/commands/convert.js.map +1 -0
  11. package/dist/commands/create.d.ts +48 -0
  12. package/dist/commands/create.d.ts.map +1 -0
  13. package/dist/commands/create.js +141 -0
  14. package/dist/commands/create.js.map +1 -0
  15. package/dist/commands/delete.d.ts +51 -0
  16. package/dist/commands/delete.d.ts.map +1 -0
  17. package/dist/commands/delete.js +122 -0
  18. package/dist/commands/delete.js.map +1 -0
  19. package/dist/commands/describe.d.ts +74 -0
  20. package/dist/commands/describe.d.ts.map +1 -0
  21. package/dist/commands/describe.js +206 -0
  22. package/dist/commands/describe.js.map +1 -0
  23. package/dist/commands/init.d.ts +37 -0
  24. package/dist/commands/init.d.ts.map +1 -0
  25. package/dist/commands/init.js +340 -0
  26. package/dist/commands/init.js.map +1 -0
  27. package/dist/commands/migrate.d.ts +65 -0
  28. package/dist/commands/migrate.d.ts.map +1 -0
  29. package/dist/commands/migrate.js +483 -0
  30. package/dist/commands/migrate.js.map +1 -0
  31. package/dist/commands/query.d.ts +56 -0
  32. package/dist/commands/query.d.ts.map +1 -0
  33. package/dist/commands/query.js +159 -0
  34. package/dist/commands/query.js.map +1 -0
  35. package/dist/commands/stats.d.ts +55 -0
  36. package/dist/commands/stats.d.ts.map +1 -0
  37. package/dist/commands/stats.js +188 -0
  38. package/dist/commands/stats.js.map +1 -0
  39. package/dist/commands/update.d.ts +50 -0
  40. package/dist/commands/update.d.ts.map +1 -0
  41. package/dist/commands/update.js +121 -0
  42. package/dist/commands/update.js.map +1 -0
  43. package/dist/config/discovery.d.ts +37 -0
  44. package/dist/config/discovery.d.ts.map +1 -0
  45. package/dist/config/discovery.js +171 -0
  46. package/dist/config/discovery.js.map +1 -0
  47. package/dist/config/loader.d.ts +49 -0
  48. package/dist/config/loader.d.ts.map +1 -0
  49. package/dist/config/loader.js +195 -0
  50. package/dist/config/loader.js.map +1 -0
  51. package/dist/index.d.ts +8 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +7 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/main.d.ts +66 -0
  56. package/dist/main.d.ts.map +1 -0
  57. package/dist/main.js +621 -0
  58. package/dist/main.js.map +1 -0
  59. package/dist/output/csv.d.ts +14 -0
  60. package/dist/output/csv.d.ts.map +1 -0
  61. package/dist/output/csv.js +54 -0
  62. package/dist/output/csv.js.map +1 -0
  63. package/dist/output/formatter.d.ts +18 -0
  64. package/dist/output/formatter.d.ts.map +1 -0
  65. package/dist/output/formatter.js +29 -0
  66. package/dist/output/formatter.js.map +1 -0
  67. package/dist/output/json.d.ts +13 -0
  68. package/dist/output/json.d.ts.map +1 -0
  69. package/dist/output/json.js +15 -0
  70. package/dist/output/json.js.map +1 -0
  71. package/dist/output/table.d.ts +18 -0
  72. package/dist/output/table.d.ts.map +1 -0
  73. package/dist/output/table.js +115 -0
  74. package/dist/output/table.js.map +1 -0
  75. package/dist/output/yaml.d.ts +13 -0
  76. package/dist/output/yaml.d.ts.map +1 -0
  77. package/dist/output/yaml.js +16 -0
  78. package/dist/output/yaml.js.map +1 -0
  79. package/dist/parsers/filter-parser.d.ts +65 -0
  80. package/dist/parsers/filter-parser.d.ts.map +1 -0
  81. package/dist/parsers/filter-parser.js +198 -0
  82. package/dist/parsers/filter-parser.js.map +1 -0
  83. package/dist/parsers/set-parser.d.ts +55 -0
  84. package/dist/parsers/set-parser.d.ts.map +1 -0
  85. package/dist/parsers/set-parser.js +198 -0
  86. package/dist/parsers/set-parser.js.map +1 -0
  87. package/dist/prompt.d.ts +58 -0
  88. package/dist/prompt.d.ts.map +1 -0
  89. package/dist/prompt.js +121 -0
  90. package/dist/prompt.js.map +1 -0
  91. package/package.json +59 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * ProseQL CLI - Delete Command
3
+ *
4
+ * Deletes an entity from a collection. Prompts for confirmation (unless --force),
5
+ * calls delete on the collection, and prints a confirmation message.
6
+ */
7
+ import * as path from "node:path";
8
+ import { createPersistentEffectDatabase, jsonCodec, makeSerializerLayer, NodeStorageLayer, tomlCodec, yamlCodec, } from "@proseql/node";
9
+ import { Effect, Layer } from "effect";
10
+ import { confirm } from "../prompt.js";
11
+ /**
12
+ * Resolve relative file paths in the config to absolute paths
13
+ * based on the config file's directory.
14
+ */
15
+ function resolveConfigPaths(config, configPath) {
16
+ const configDir = path.dirname(configPath);
17
+ const resolved = {};
18
+ for (const [collectionName, collectionConfig] of Object.entries(config)) {
19
+ if (collectionConfig.file && !path.isAbsolute(collectionConfig.file)) {
20
+ resolved[collectionName] = {
21
+ ...collectionConfig,
22
+ file: path.resolve(configDir, collectionConfig.file),
23
+ };
24
+ }
25
+ else {
26
+ resolved[collectionName] = collectionConfig;
27
+ }
28
+ }
29
+ return resolved;
30
+ }
31
+ /**
32
+ * Execute the delete command.
33
+ *
34
+ * Boots the database from the config, prompts for confirmation (unless --force),
35
+ * and deletes the entity from the specified collection.
36
+ *
37
+ * @param options - Delete command options
38
+ * @returns Effect that resolves to the delete result
39
+ */
40
+ export function runDelete(options) {
41
+ return Effect.gen(function* () {
42
+ const { collection, id, config, configPath, force = false } = options;
43
+ // Check if collection exists in config
44
+ if (!(collection in config)) {
45
+ const availableCollections = Object.keys(config).join(", ");
46
+ return {
47
+ success: false,
48
+ message: `Collection '${collection}' not found in config. Available collections: ${availableCollections || "(none)"}`,
49
+ };
50
+ }
51
+ // Prompt for confirmation
52
+ const confirmResult = yield* Effect.promise(() => confirm({
53
+ message: `Delete entity '${id}' from collection '${collection}'?`,
54
+ force,
55
+ }));
56
+ if (!confirmResult.confirmed) {
57
+ return {
58
+ success: false,
59
+ message: "Delete operation cancelled.",
60
+ aborted: true,
61
+ };
62
+ }
63
+ // Resolve relative file paths in the config
64
+ const resolvedConfig = resolveConfigPaths(config, configPath);
65
+ // Build the persistence layer for database operations
66
+ const PersistenceLayer = Layer.merge(NodeStorageLayer, makeSerializerLayer([jsonCodec(), yamlCodec(), tomlCodec()]));
67
+ // Boot the database and execute the delete
68
+ const program = Effect.gen(function* () {
69
+ const db = yield* createPersistentEffectDatabase(resolvedConfig, {});
70
+ // Get the collection (type assertion needed since we check collection existence above)
71
+ const coll = db[collection];
72
+ // Execute the delete operation
73
+ yield* coll.delete(id);
74
+ return { deleted: true };
75
+ });
76
+ // Run the program with the persistence layer
77
+ const result = yield* program.pipe(Effect.provide(PersistenceLayer), Effect.scoped, Effect.catchAll((error) => {
78
+ // Extract error message based on error type
79
+ let message;
80
+ if (error && typeof error === "object") {
81
+ const errorObj = error;
82
+ if ("_tag" in errorObj && typeof errorObj.message === "string") {
83
+ // Tagged error with message field
84
+ message = errorObj.message;
85
+ }
86
+ else if (error instanceof Error) {
87
+ message = error.message;
88
+ }
89
+ else {
90
+ message = String(error);
91
+ }
92
+ }
93
+ else {
94
+ message = String(error);
95
+ }
96
+ return Effect.succeed({
97
+ success: false,
98
+ message: `Delete failed: ${message}`,
99
+ });
100
+ }));
101
+ // Check if we got an error result
102
+ if ("success" in result && result.success === false) {
103
+ return result;
104
+ }
105
+ // Success - entity was deleted
106
+ return {
107
+ success: true,
108
+ message: `Successfully deleted entity '${id}' from collection '${collection}'.`,
109
+ };
110
+ });
111
+ }
112
+ /**
113
+ * Handle the delete command from CLI main.ts.
114
+ * This is the entry point called by the command dispatcher.
115
+ *
116
+ * @param options - Delete command options
117
+ * @returns Promise that resolves to the delete result
118
+ */
119
+ export async function handleDelete(options) {
120
+ return Effect.runPromise(runDelete(options));
121
+ }
122
+ //# sourceMappingURL=delete.js.map
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;SAC/E,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,OAAsB;IAEtB,OAAO,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * ProseQL CLI - Describe Command
3
+ *
4
+ * Boots the database from config, reads the schema for the named collection,
5
+ * and displays field names, types, optional/required status, indexes,
6
+ * relationships, and constraints.
7
+ */
8
+ import type { DatabaseConfig } from "@proseql/core";
9
+ import { Effect } from "effect";
10
+ /**
11
+ * Options for the describe command.
12
+ */
13
+ export interface DescribeOptions {
14
+ /** The database configuration */
15
+ readonly config: DatabaseConfig;
16
+ /** The name of the collection to describe */
17
+ readonly collection: string;
18
+ }
19
+ /**
20
+ * Information about a single field in the schema.
21
+ */
22
+ export interface FieldInfo {
23
+ readonly name: string;
24
+ readonly type: string;
25
+ readonly required: boolean;
26
+ readonly indexed: boolean;
27
+ readonly unique: boolean;
28
+ }
29
+ /**
30
+ * Information about a relationship.
31
+ */
32
+ export interface RelationshipInfo {
33
+ readonly name: string;
34
+ readonly type: "ref" | "inverse";
35
+ readonly target: string;
36
+ readonly foreignKey: string | undefined;
37
+ }
38
+ /**
39
+ * Result of the describe command.
40
+ */
41
+ export interface DescribeResult {
42
+ readonly success: boolean;
43
+ readonly message?: string;
44
+ readonly data?: {
45
+ readonly collection: string;
46
+ readonly fields: ReadonlyArray<FieldInfo>;
47
+ readonly relationships: ReadonlyArray<RelationshipInfo>;
48
+ readonly indexes: ReadonlyArray<string | ReadonlyArray<string>>;
49
+ readonly uniqueConstraints: ReadonlyArray<string | ReadonlyArray<string>>;
50
+ readonly hasSearchIndex: boolean;
51
+ readonly searchIndexFields: ReadonlyArray<string>;
52
+ readonly version: number | undefined;
53
+ readonly appendOnly: boolean;
54
+ };
55
+ }
56
+ /**
57
+ * Execute the describe command.
58
+ *
59
+ * Reads the schema from the config for the named collection and extracts
60
+ * detailed information about fields, types, indexes, relationships, etc.
61
+ *
62
+ * @param options - Describe command options
63
+ * @returns Result with collection schema information or error message
64
+ */
65
+ export declare function runDescribe(options: DescribeOptions): Effect.Effect<DescribeResult>;
66
+ /**
67
+ * Handle the describe command from CLI main.ts.
68
+ * This is the entry point called by the command dispatcher.
69
+ *
70
+ * @param options - Describe command options
71
+ * @returns Promise that resolves to the describe result or rejects on error
72
+ */
73
+ export declare function handleDescribe(options: DescribeOptions): Promise<DescribeResult>;
74
+ //# sourceMappingURL=describe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../../src/commands/describe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,MAAM,EAA0B,MAAM,QAAQ,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE;QACf,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;QAC1C,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;QACxD,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAChE,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1E,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;QACjC,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QACrC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;KAC7B,CAAC;CACF;AA4JD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAC1B,OAAO,EAAE,eAAe,GACtB,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CA4C/B;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CACnC,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,cAAc,CAAC,CAGzB"}
@@ -0,0 +1,206 @@
1
+ /**
2
+ * ProseQL CLI - Describe Command
3
+ *
4
+ * Boots the database from config, reads the schema for the named collection,
5
+ * and displays field names, types, optional/required status, indexes,
6
+ * relationships, and constraints.
7
+ */
8
+ import { Effect, SchemaAST } from "effect";
9
+ /**
10
+ * Convert an AST type to a human-readable type name.
11
+ */
12
+ function astTypeToString(ast) {
13
+ switch (ast._tag) {
14
+ case "StringKeyword":
15
+ return "string";
16
+ case "NumberKeyword":
17
+ return "number";
18
+ case "BooleanKeyword":
19
+ return "boolean";
20
+ case "BigIntKeyword":
21
+ return "bigint";
22
+ case "SymbolKeyword":
23
+ return "symbol";
24
+ case "UndefinedKeyword":
25
+ return "undefined";
26
+ case "VoidKeyword":
27
+ return "void";
28
+ case "NeverKeyword":
29
+ return "never";
30
+ case "UnknownKeyword":
31
+ return "unknown";
32
+ case "AnyKeyword":
33
+ return "any";
34
+ case "ObjectKeyword":
35
+ return "object";
36
+ case "Literal": {
37
+ const value = ast.literal;
38
+ if (typeof value === "string") {
39
+ return `"${value}"`;
40
+ }
41
+ return String(value);
42
+ }
43
+ case "UniqueSymbol":
44
+ return `unique symbol`;
45
+ case "Enums":
46
+ return `enum(${ast.enums.map(([name]) => name).join(" | ")})`;
47
+ case "TemplateLiteral":
48
+ return "template literal";
49
+ case "TupleType": {
50
+ const elements = ast.elements.map((e) => astTypeToString(e.type));
51
+ const rest = ast.rest.map((r) => `...${astTypeToString(r.type)}`);
52
+ return `[${[...elements, ...rest].join(", ")}]`;
53
+ }
54
+ case "TypeLiteral": {
55
+ if (ast.propertySignatures.length === 0 &&
56
+ ast.indexSignatures.length === 0) {
57
+ return "{}";
58
+ }
59
+ if (ast.propertySignatures.length > 0) {
60
+ return "object";
61
+ }
62
+ return "Record";
63
+ }
64
+ case "Union": {
65
+ const types = ast.types.map((t) => astTypeToString(t));
66
+ // Simplify common patterns
67
+ if (types.length === 2 && types.includes("undefined")) {
68
+ const other = types.find((t) => t !== "undefined");
69
+ return `${other} | undefined`;
70
+ }
71
+ if (types.length <= 4) {
72
+ return types.join(" | ");
73
+ }
74
+ return `union(${types.length} types)`;
75
+ }
76
+ case "Suspend":
77
+ return "recursive";
78
+ case "Refinement":
79
+ return astTypeToString(ast.from);
80
+ case "Transformation":
81
+ return astTypeToString(ast.to);
82
+ case "Declaration": {
83
+ // Try to get identifier annotation
84
+ const identifier = ast.annotations[SchemaAST.IdentifierAnnotationId];
85
+ if (typeof identifier === "string") {
86
+ return identifier;
87
+ }
88
+ return "declaration";
89
+ }
90
+ default:
91
+ return "unknown";
92
+ }
93
+ }
94
+ /**
95
+ * Check if a field is in any of the indexes (single or compound).
96
+ */
97
+ function isFieldIndexed(fieldName, indexes) {
98
+ if (!indexes)
99
+ return false;
100
+ return indexes.some((index) => {
101
+ if (typeof index === "string") {
102
+ return index === fieldName;
103
+ }
104
+ return index.includes(fieldName);
105
+ });
106
+ }
107
+ /**
108
+ * Check if a field has a unique constraint (single or compound).
109
+ */
110
+ function isFieldUnique(fieldName, uniqueFields) {
111
+ if (!uniqueFields)
112
+ return false;
113
+ return uniqueFields.some((constraint) => {
114
+ if (typeof constraint === "string") {
115
+ return constraint === fieldName;
116
+ }
117
+ // For compound constraints, only mark as unique if it's the only field
118
+ return constraint.length === 1 && constraint[0] === fieldName;
119
+ });
120
+ }
121
+ /**
122
+ * Extract field information from a schema.
123
+ */
124
+ function extractFieldInfo(schema, config) {
125
+ const ast = schema.ast;
126
+ const propertySignatures = SchemaAST.getPropertySignatures(ast);
127
+ return propertySignatures.map((ps) => ({
128
+ name: String(ps.name),
129
+ type: astTypeToString(ps.type),
130
+ required: !ps.isOptional,
131
+ indexed: isFieldIndexed(String(ps.name), config.indexes),
132
+ unique: isFieldUnique(String(ps.name), config.uniqueFields),
133
+ }));
134
+ }
135
+ /**
136
+ * Extract relationship information from the config.
137
+ */
138
+ function extractRelationships(relationships) {
139
+ return Object.entries(relationships).map(([name, rel]) => ({
140
+ name,
141
+ type: rel.type,
142
+ target: rel.target,
143
+ foreignKey: rel.foreignKey,
144
+ }));
145
+ }
146
+ /**
147
+ * Execute the describe command.
148
+ *
149
+ * Reads the schema from the config for the named collection and extracts
150
+ * detailed information about fields, types, indexes, relationships, etc.
151
+ *
152
+ * @param options - Describe command options
153
+ * @returns Result with collection schema information or error message
154
+ */
155
+ export function runDescribe(options) {
156
+ // This is a pure synchronous operation - no effects needed
157
+ return Effect.sync(() => {
158
+ const { config, collection } = options;
159
+ // Check if the collection exists
160
+ const collectionConfig = config[collection];
161
+ if (!collectionConfig) {
162
+ const availableCollections = Object.keys(config);
163
+ return {
164
+ success: false,
165
+ message: `Collection "${collection}" not found. Available collections: ${availableCollections.join(", ") || "(none)"}`,
166
+ };
167
+ }
168
+ // Extract field information from the schema
169
+ const fields = extractFieldInfo(collectionConfig.schema, collectionConfig);
170
+ // Extract relationships
171
+ const relationships = extractRelationships(collectionConfig.relationships);
172
+ // Get other config properties
173
+ const indexes = collectionConfig.indexes ?? [];
174
+ const uniqueConstraints = collectionConfig.uniqueFields ?? [];
175
+ const searchIndexFields = collectionConfig.searchIndex ?? [];
176
+ const hasSearchIndex = searchIndexFields.length > 0;
177
+ const version = collectionConfig.version;
178
+ const appendOnly = collectionConfig.appendOnly ?? false;
179
+ return {
180
+ success: true,
181
+ data: {
182
+ collection,
183
+ fields,
184
+ relationships,
185
+ indexes,
186
+ uniqueConstraints,
187
+ hasSearchIndex,
188
+ searchIndexFields,
189
+ version,
190
+ appendOnly,
191
+ },
192
+ };
193
+ });
194
+ }
195
+ /**
196
+ * Handle the describe command from CLI main.ts.
197
+ * This is the entry point called by the command dispatcher.
198
+ *
199
+ * @param options - Describe command options
200
+ * @returns Promise that resolves to the describe result or rejects on error
201
+ */
202
+ export async function handleDescribe(options) {
203
+ const result = await Effect.runPromise(runDescribe(options));
204
+ return result;
205
+ }
206
+ //# sourceMappingURL=describe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.js","sourceRoot":"","sources":["../../src/commands/describe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,MAAM,EAAe,SAAS,EAAE,MAAM,QAAQ,CAAC;AAoDxD;;GAEG;AACH,SAAS,eAAe,CAAC,GAAkB;IAC1C,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,eAAe;YACnB,OAAO,QAAQ,CAAC;QACjB,KAAK,eAAe;YACn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AU,uCAAuC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,EAAE;aACtH,CAAC;QACH,CAAC;QAED,4CAA4C;QAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QAE3E,wBAAwB;QACxB,MAAM,aAAa,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAE3E,8BAA8B;QAC9B,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC;QAC/C,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,YAAY,IAAI,EAAE,CAAC;QAC9D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,WAAW,IAAI,EAAE,CAAC;QAC7D,MAAM,cAAc,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;QACzC,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,IAAI,KAAK,CAAC;QAExD,OAAO;YACN,OAAO,EAAE,IAAI;YACb,IAAI,EAAE;gBACL,UAAU;gBACV,MAAM;gBACN,aAAa;gBACb,OAAO;gBACP,iBAAiB;gBACjB,cAAc;gBACd,iBAAiB;gBACjB,OAAO;gBACP,UAAU;aACV;SACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,OAAwB;IAExB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * ProseQL CLI - Init Command
3
+ *
4
+ * Scaffolds a new proseql project with config and data files.
5
+ * Checks for existing config and aborts with warning if found.
6
+ */
7
+ /**
8
+ * Options for the init command.
9
+ */
10
+ export interface InitOptions {
11
+ readonly format?: string;
12
+ readonly cwd?: string;
13
+ }
14
+ /**
15
+ * Result of the init command.
16
+ */
17
+ export interface InitResult {
18
+ readonly success: boolean;
19
+ readonly message: string;
20
+ readonly createdFiles?: readonly string[];
21
+ }
22
+ /**
23
+ * Execute the init command.
24
+ *
25
+ * Checks for existing config files and aborts if found.
26
+ * Creates proseql.config.ts with an example collection definition.
27
+ *
28
+ * @param options - Init command options
29
+ * @returns Result indicating success or failure
30
+ */
31
+ export declare function runInit(options?: InitOptions): InitResult;
32
+ /**
33
+ * Handle the init command from CLI main.ts
34
+ * This is the entry point called by the command dispatcher.
35
+ */
36
+ export declare function handleInit(options?: InitOptions): Promise<void>;
37
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkPH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CAuF7D;AAiCD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASzE"}